Animation Playing While Loading Scene One to Other in C# Unity3D? - c#

I need to know about Animation Playing While Loading Scene One to Other in C# Unity3D.
I am using the below code to Navigation. It navigates to Scene2, but it doesn't looks very good.
Application.LoadLevel ("Scene2");
How can I apply a loading animation while the level loads?

From http://answers.unity3d.com/questions/39317/animated-loading-screen.html:
Create a scene that will be your loading screen, do what you want to do with this scene (an animation or whatever you want). Don't forget to make this small to load.
Create an object with a script and in the Update function of this script just put these lines:
if(Application.GetStreamProgressForLevel("Scene2") ==1){
Application.LoadLevel("Scene2");
}
Make sure that you put these scenes in order when publishing:
LoadScreen
Scene1
LoadScreen
Scene2
The Application.GetStreamProgressForLevel() function returns a float number between 0 and 1, you can use this to make a progress bar too.
Additional reading:
http://forum.unity3d.com/threads/loading-screen.38405/
http://forum.unity3d.com/threads/adding-loading-screen-while-unity-is-getting-loaded.17298/

Create new scene (loading) Coding you're loading screen
Or use this resource :https://www.assetstore.unity3d.com/en/#!/content/6354
then after you create the loading scene
use this code (scene (loading)) add the code after the level finish
Application.LoadLevel("loading");
and on loading scene change the name of level use this to navigate you to next level
Application.LoadLevel("level2");

Related

dont unload scene when switching to another scene

i have 2 scene in my program, when click a button go to the second scene and when press home button (in the second scene) go to the previous scene, how can keep loaded the first scene? I tried the Scene Manager additive mode but it shows both scenes together, how can i do this?
If you want to keep the first scene loaded but hidden when the second scene is shown, it is not possible. But what you might want to try is to use SceneManager.LoadSceneAsync when you call the first scene from the second scene
I don't know the code but i am pretty sure you can find all the children of the scene make them setActive(false) and make everything hidden.
You need to use Scene Manager additive mode ofcourse.

Can't change to the specific scenes using UI buttons in unity, why?

So, to start, I have this code:
public void switcher(string scene_name)
{
SceneManager.LoadScene(scene_name, LoadSceneMode.Single);
}
That's supposed to load a scene given in the editor, and I have 2 buttons, each supposed to load a specific scene and 2 gameobjects (one for scene) that have the code written before.
Object with script
Button that calls object
Now, the thing is, despite having different scene names, both buttons load the same scene, and when I do some changes (mainly deleting and re-adding components) then both buttons load another scene, but never one scene each.
Why is this happening?
First of all to load your scene you must add it to the build settings.Go to File>Build settings and then drag your scene into the Scenes in build.Sencond thing you must add this line of code to set you scene to be the active one
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + *Add you scene number here*);

Trying to totally reload scene

I made a scene that represents the main menu of a game. In this menu there is an option for single player, and, when I press it, it opens a new "level 1" scene.
Also, there is a pause menu that allows the player to quit the game and get back to the main menu.
However, after it backs to the main menu, when I try to get into the level 1 scene using SceneManager.LoadScene("level 1"), it makes a lot of problems. It means that a lot of game objects don't act like they should.
I dont know why it happened, and I would appreciate if someone can help me solve it. Thank you.
You can use SceneManager.LoadScene("level 1", LoadSceneMode.Single); to clear the old scene and only load the new one in, which will let you get a clear scene and shouldn't have any problems.
If you have scripts that need to last into the new scene, you can use DontDestroyOnLoad(this); in your scripts and they will move into the new scene. The problem is you have to make sure your scripts that aren't being destroyed don't try and access destroyed objects. From your comment it looks like you have a player movement controller that isn't being destroyed, or it's being created in the menu scene and it doesn't have it's references updated correctly when the scene is reloaded. You can also use Destroy(this); in your scripts that are saved through scene changes to get rid of them when they're done running.

Strange plane behavior in Unity3D while changing scene

I am a beginner with Unity3D.
Until now I have learned a few things.
For example, create a simple 2D menu, switch from one scene to another with an appropriate C# script and associate the scripts with the objects.
The problem I pose here is about the behavior (strange to me) of the white panel behind the menu when I change the scene.
I have two scenes, the first which is the menu and a second one is the actual game.
I used UI elements to create the first one, while I used 3D objects to make the second one.
So, what happens?
It happens that when you step into the second scene by clicking on the green button the background becomes brown. If, on the other hand, I run the second scene individually without going through the first one (launching the scene directly), the background remains white.
See this short video for further details.
Why?
Listed below are some images, hoping they can help me understand my problem.
The first scene (dev mode):
The first scene (running):
The second scene (dev mode):
The second scene (running directly):
The second scene (running after clicking the green button "Comincia"):
The script I use to change the scene (linked to the green button):
using UnityEngine.SceneManagement;
using UnityEngine;
public class GameScene : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void PlayNow () {
SceneManager.LoadScene("Game", LoadSceneMode.Single);
}
}
Update: I have updated the information on the application. I added a new screenshot where you can see the camera settings. Meanwhile, I changed some things, but the problem still remains. I also noticed that this problem only happens when I switch to the Game scene, when I switch to other scenes instead it does not.
Added a new screenshot showing the inspector of the Main Camera object:
I was able to understand where the problem was: I made an improper use of the Plane object (highlighted in the screenshot). By removing it, now it shows correctly the solid color white background as set on the Main Camera.

Non-legacy animation cannot be stopped / controlled

I made an animation using Animation panel, which swaps images from time to time. Read from the Internet, this is not a legacy animation.
Here is the Animation panel screenshot:
Then, I add the Animation and Animator components to the Game Object and assign the animation, which is called Animation01, to it. Here is the screenshot from Inspector of the Game Object:
I try to use the following C# script to stop the animation :
using UnityEngine;
using System.Collections;
public class Scene1 : MonoBehaviour {
public GameObject ball;
// Use this for initialization
void Start () {
ball.animation.Stop();
}
// Update is called once per frame
void Update () {
}
}
but the animation didn't stop. It prompts a notice in Console:
Default clip could not be found in attached animations list.
What did I miss?
UPDATE: By disabling/ removing Animator component, the animation is stopped and cannot be controlled by codes. I need to control the animation by codes.
Unity had implemented two animation systems throughout it's history. Animation component belongs to the legacy animation system, while Animator component belongs to the new animation system. So, adding both components makes no sense: you either use the old system or the new.
The main difference between the legacy and new animation system is that the new animation system is much more advanced in way it's controlled. However, it also means that it's more complicated. It adds another level of abstraction: instead of launching animation yourself, you control variables that influence the behaviour of a special state machine, animation controller.
So, if you want to use animations for something really, really simple, where you want just to launch animations manually, it may be better to use legacy animation system instead. But the components are not the only thing that is different: the animation files themselves are marked to determine if they are "legacy" or not. By default, when you create an animation in the new unity version, it belongs to the new animation system. If you want to use it with a legacy animation, you have to mark it as a legacy animation. Unfortunately, you'll have to do a little hack to achieve that.

Categories