- Home /
Scripting Next level with Animation
EDIT: Don't think this was clear, it proceeds to the next level but doe's not do the animation. (Doe's the delay before changing level.)
Okay, so for my project I have created a collision box that will take me to the next level and have some delay that I need to have an animation go through (FadeOut). I have the animation itself connected to a transparent plane that is assigned to the player himself. But I can't figure out how to get the animation to actually run during the delay and also making it run from the plane itself. (During the delay no animation starts to play.)
public class LoadLevel : MonoBehaviour
{
public enum LoadType
{
ResetCurrent = 0,
LoadIndex = 1,
LoadName = 2,
}
public LoadType Load = LoadType.ResetCurrent;
public int Index = 0;
public string Name = "Default";
public float DelayTimer = 5.0f;
bool StartTimer = false;
void Update ()
{
if ( StartTimer )
{
DelayTimer -= Time.deltaTime;
if ( DelayTimer < 0 )
{
LoadTheLevel();
}
}
}
public void OnTriggerEnter(){
StartTimer = true;
animation.Play ("FadeOutAnimation");
}
public void LoadTheLevel ()
{
if(Load == LoadType.ResetCurrent)
{
Application.LoadLevel(Application.loadedLevel);
}
else if(Load == LoadType.LoadIndex)
{
Application.LoadLevel(Index);
}
else if(Load == LoadType.LoadName)
{
Application.LoadLevel(Name);
}
}
}
So you aren't getting the collision I imagine. Thats public void OnTriggerEnter(Collider other) plus you need a rigidbody (is$$anonymous$$inematic = true if you don't want physics) attached to the player.
Sorry whydoidoit, that didn't work. Also forgot to clearly state it changes level and that the delay works, just the animation to fade doe's not work. Sorry for the confusion. Thanks for the reply though.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Is it possible to manipulate Mecanim state machine / blend trees from scripting? 0 Answers
Created Animations only play half within Animator 0 Answers
Resetting a combo attack chain if next attack did not occur in time 1 Answer
Animation Script Help 1 Answer