Game Development Reference
In-Depth Information
That finishes the animation part. We now have an end-to-end animation that will
play the loading animation when we tell it we are Loading ; it will also stop the
animation when we tell it we are not Loading .
Now we need to tell the animation when the game is Loading . To do this we'll add
a script to play the animation when the scene starts.
Create a new C# script called LoadingAnimation in the Assets\Scripts folder and
replace its contents with the following:
using System.Collections;
using UnityEngine;
public class LoadingAnimation : MonoBehaviour {
Animator loadingAnimation;
// Get the Animator component on Awake
void Awake () {
loadingAnimation = GetComponent<Animator>();
}
// Start the loading animation by setting the animation
// Loading property to true
void Start () {
loadingAnimation.SetBool("Loading", true);
StartCoroutine(LoadLevel());
}
// A simple coroutine to wait 3 seconds and load the level
IEnumerator LoadLevel()
{
for (int i = 0; i < 3; i++)
{
yield return new WaitForSeconds(1);
}
loadingAnimation.SetBool("Loading", false);
//Application.LoadLevel("Main Menu");
}
}
This is just a simple script that gets the reference to the Animation and starts it by
setting the Loading property of the Animation to true , after 3 seconds it then stops
the animation to load a level. (Which is commented out, as it's just an example.)
Attach this script to the LoadingLogo GameObject, and now you have a very simple
UI loading animation, which will work with any of the Filled Image Type options.
 
Search WWH ::




Custom Search