I have a level selection menu, inside this I have buttons to load my scene levels.
I am using the next method to switch the scenes:
UnityEngine.SceneManagement.SceneManager.LoadScene();
The problem is that I have dark-gray faders in my scene and when I load the different scenes the screen flashes white. Instead of staying in the same dark-gray tone like I would want it.
I will gladly supply any further information that you need.
Does anyone know a solution?
The last frame of the previous scene is contiguous with the first frame of the next scene so one needs to ensure that there is nothing in either frame that could make a visible difference e.g. resetting the state of something like a material colour via a script called from an Awake function.
Related
I have a character selection screen that displays a confirmation screen and when selecting, a coroutine is started, a burst of particles fly into the screen and the new level is loaded - this is to delay the loading of the level so the particles can fill the screen.
This all works as intended when I test it by directly loading the scene (character selection) on the Unity editor, however, if I'm doing a full test and I come from (Start Screen) I can do everything and the debug says it is registering everything, however the particles don't show up and the loading doesn't execute.
Also, the console doesn't display any errors.
I've tried everything (Stop coroutine, using a while(true) ...) but can't figure out why it doesn't load. Code below:
The UI button has LoadEloise() as the method that gets triggered when clicking on it.
Code below:
Tried stopping coroutine right before activating it and also on Start, also making sure that the particle system is set to Active(false) before then being activated again.
IEnumerator DelayLoad()
{
heartExplosion[explosionNumber].gameObject.SetActive(true);
yield return new WaitForSeconds(1);
SceneManager.LoadScene(sceneName);
}
public void LoadEloise()
{
sceneName = "Eloise";
explosionNumber = 10;
StartCoroutine(DelayLoad());
}
Expected result: particle system is activated, covering the screen, and then after one second new scene is loaded.
This is a video showing the expected result, achieved by starting the test from the scene that hosts the coroutine: https://www.youtube.com/watch?v=BQAgzJ-HJB4&feature=youtu.be
Actual result: nothing, no errors, no particles nothing. The button is shown as pressed from the graphic point of view but nothing happens.
This is a video showing what happens when starting the code from the previous scene: https://www.youtube.com/watch?v=WhEzi9Qjvg8&feature=youtu.be
Is your LoadEloise function even getting called?
If it was just a matter of the particles not getting displayed then it could have been a case of something like the canvas sorting order not being set properly for the particle system/container but if the subsequent scene loading is also not happening then you need to check two things first:
Add breakpoints/debug statements to follow the order of the execution of code and make sure that the correct functions are getting called in the order they are supposed to.
If all the functions are getting called and you don't see any error related to scene loading then it could be related to how the scene is set up when loaded externally. Add breakpoints/debug calls in the initialization function for the new scene to ensure that it has been loaded and is in place, make sure the position/scale of the content is not set to some weird value when the scene is loaded and check the hierarchy to locate the scene content in the editor window to make sure that the visual elements are set up properly.
I have made block breaker game in unity 4.6 and i have added 3 levels. If anyone loses in any level say level_02 then the lose screen showing game over loads up. When he clicks try again it loads the start screen as i have ordered them in my build settings. I want my game to load the same level where the user have lost so that he clicks try again and the same level loads again i.e level_02.
You can save the current levelScene name before you loads the looseScene like,
PlayerPrefs.SetString("LastLevelName",ScaneManager.GetActiveScene().name);
and when you click the restart button in looseScene then call some method like this,
public void RestartSameLevel(){
SceneManager.LoadScene(PlayerPrefs.GetString("LastLevelName","DefaultSceneName");
//"DefaultSceneName" can be your StartScene name
}
You can restart the scene
Application.LoadLevel(Application.loadedLevel)
Or
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name);
I have two scenes: Menu and Game. I'm using C#.
When you die in the game, you get sent back to the menu with
SceneManager.LoadScene("Menu");
There's a script with a GUIButton in the menu that, when clicked, loads the game with
SceneManager.LoadScene("Game");
What I want to happen is that when I click the button in the menu scene, it loads the game as if I just clicked the play button with the game scene open in the editor.
What instead happens is that it goes to the game scene, but some objects from the game scene appear to be missing. I'm not using DontDestroyOnLoad() anywhere.
Some objects from the scene do appear, but others don't. The weirdest thing is that there are some data fields on a script on the missing object that are referred to by some other scripts, and those give values that make sense.
Does anyone have any idea what's going on, or what I can do to get the desired result?
Turns out that the problem was that I was destroying one of my objects if it was not the first time that object was created, and I didn't realize it.
are those static objects or dynamic? try to instantiate them in function which gets called on scene loaded.
I am using the unity engine to make a "open world" (I'm using this loosely because its mostly the same) MMO top-down shooter. I have made the world, I have a really fast system to only load the part of the world you are standing on, But It still takes 5 or 6 minutes for it to load from the play button. basically what i have done is have a massive grid of tiles split up into 8x8 sections, and those into 12x12 regions. I would like a way to load the world as you go (like from a bitmap image or something), but would I also want to be able to edit and change the world in the editor. Anybody who has done this before can you help me figure out what to do?
Just off of the top of my head, I haven't used this in a released product but you can split your large scene into multiple scenes, you said you 8x8 tiles by 12x12 regions.
I would suggest making a base scene, that loads where the player is in the world, based off of his position you load a scene and a few scenes around him, as he navigates the world or gets to a place you determine would be in range for him to see other items you load the next scene. This is what it would look like:
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOXXOOOO
OOOOOXXXOOOO
OOOOOOXOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
OOOOOOOOOOOO
each O represents a scene, and the X's are loaded scene. How do you load multiple scenes at the same time? If you take a look at the overloaded methods for SceneManager.LoadScene there is a method that takes in a LoadSceneMode Passing LoadSceneMode.Additive Will load a new scene into your world. without unloading the previous scene. So depending on how intensive your game is, you could Just load the surrounding area's to the player and load them over time in the background. The other option is to hold which scenes are currently loaded.
Next issue, being able to edit and change the world in the editor. Inside of the Unity Editor you can have multiple scenes open at once, and move and relocate each item in those scenes. The scary thing about this though, is to add a new GameObject to a specific scene you have to have that scene set as the active scene.
Here is a link to the documentation on Multi-Scene editting:
https://docs.unity3d.com/Manual/MultiSceneEditing.html
Documentation on SceneManager.LoadScene:
https://docs.unity3d.com/2018.1/Documentation/ScriptReference/SceneManagement.SceneManager.LoadScene.html
Documentation on LoadSceneMode.Additive:
https://docs.unity3d.com/2018.1/Documentation/ScriptReference/SceneManagement.LoadSceneMode.Additive.html
I am wanting to make a birds-eye view pixel-art game.
I currently have two sprite sheets set up, and split and whatnot
groundSheet and characterSheet these are split up into
ground_0_0_0 (A concrete floor)
ground_1_0_0 (grass)
character_0_0_0 (man idle animation frame 1)
character_0_0_1 (man idle animation frame 2)
character_0_1_0 (man run animation frame 1)
character_0_1_1 (man run animation frame 2)
character_1_0_0 (woman idle animation frame 1)
character_1_0_1 (woman idle animation frame 2)
character_1_1_0 (woman run animation frame 1)
character_1_1_1 (woman run animation frame 2)
The numbers after are a note as to:
first number - the main set of sprite animations (eg man)
second number - the animation set in use (eg run or idle)
third number - the frame of said animation.
(the ground has this as i plan to have animated grounds late on)
Now, I wish to make a script for the character (and ground alike) that has an editable value that is view able in the unity editor, for example how things like the sprite renderer has sprite, colour etc. Which dictates what first number to use (see above) what second number and the delay for the animation of the third number. This will then tell the sprite renderer what pictures to load and how quickly to load them. I also wish for the script to scan for the file starting with for example character_0_0_ and then count how many files after it, so it knows what to do when animating. I would like this script to be checking for a change in one of the variables viewable in the unity editor to change and as soon as it does it checks everything it needs for an animtion.
Something else could be done where there is only 1 box to edit in unity, which you put character_0_0_ or ground_1_0_ or something similar, and it checks everything that way (it also makes the script universal, and usable on the ground, character and walls (which I am adding later)).
This may seem confusing, but it make sense for me and many of you will probably mention a much easier way to do animations and such, but please only say these if it does what I want above.
For scripts and such my file layout:
/Assets
/scripts
ground.cs
character.cs
/sprites
characterSheet.png
character_0_0_0
character_0_0_1
character_0_1_0
character_0_1_1
character_1_0_0
character_1_0_1
character_1_1_0
character_1_1_1
groundSheet.png
ground_0_0_0
ground_1_0_0
(For some reason Stack overflow said the above was code, so i had to make it as that)
ground.cs and character.cs are the scripts in which I want to made as explained above.
In my object view thingy I have
Main Camera
ground
character
I am practically a newb to C# and JS I know bascially the grammar of C# (like where to use {} and put ; at the end of the lines). If you help me with this, i request that you explain the script, like use the // thing to simply explain what each command does, I know a few but not all of them. And I know someone is going to say it is really well documented in tutorial X and such, but most tutorials are not in unity 5 and while helping with the matter do not touch on it exactly.
Thank you for your help, if there is anything about this question/request that you do not understand (It is pretty complex) I will explain.
Maybe I am completely wrong, but it seems to me that you are trying to recreate an Animation system.
Is there a specific reason for which you wouldn't use Unity's animation system?
You can do everything that you describe here with it (change sprite, choose animation speed). And you would have almost no code to write. Just drag and drop you sprites in the editor for a start
EDIT - answer to first comment:
What you should do is create all the animations you need. Then in the animator, you choose which condition will trigger a transition to another animation (for instance, boolean jump is true will transition to animation jump). Then in your code you can call GetComponent().SetBool("Jump", true).
To have different character, you can create different gameObjects (one per character). They all have a different animator with animations specific to the character.
The other solutiojn if you really want one one gameObject and one animator is that you also add string condition to you animation (example, if character=="character1" and jump==true, transition to jump animation).
If I were you I would really focus on testing and learning all you can do with Unity animator. I can't think of a case were you would need to recreate the animation system yourself
Your question was long winded and hard to understand but ill try to help,
firstly if you want editable values in the unity editor I would Suggest using a serialized structure of information like this
[System.Serializable] // this makes it viewable in the inspector
public struct Sprite_Manager;
{
public Sprite[] Render_Sprites; // array of sprites to store sprites
public SpriteRenderer S_Renderer;
public float Anim_Delay;
}
public class Character : MonoBehavior {
Sprite_Manager SMG = new Sprite_Manager(); // instantiate a new instance of the struct
void Set_Sprite()
{
for(int i = 0; i < SMG.Render_Sprites.Length; i++)
{
SMG.S_Renderer.sprite = SMG.Render_Sprites[i];
}
}
void Update
{
Invoke("Set_Sprite", SMG.Anim_Delay);
}
}
Not sure if this is exactly what your looking for but this is one way you could setup a structure of sprite based information and use Invoke to setup some sort of delay when passing new sprites to the renderer.