- Home /
How to add WAKE_UP animation before the character enters IDLE state?
Hi, i have a character in my game on which I want to execute the animation "Wake Up", before the I can move the object around. I think the way my Animator Controller handles that is incorrect. I have two BOOL parameter isAwake
and isIDLE
which I handle though C# scripts. See scripts below:
Script for character:
private void Start () {
//Store GameObject's Components
animator = GetComponent<Animator>(); //Get Animator Controller
controller = GetComponent<CharacterController>(); //Get Character Controller
rb = GetComponent<Rigidbody>(); //Get Rigid Body
MyCameraPrefab = Camera.main;
EffectsAudioSourceController = GetComponent<AudioSource>(); //Set Audio
animator.SetBool("isAwake", false);
animator.SetBool("isIDLE", false);
}
// Update is called once per
private void Update () {
/* (RE)SET ANIMATION - IDLE */
if (animator.GetBool("isAwake") == true && animator.GetBool("isIDLE") == true)
{
Animation_IDLE();
}
//CALL THIS FROM ANOTHER SCRIPT
public void Animation_WakeUP() {
animator.SetBool("isIDLE", false);
animator.SetBool("isAwake", true);
}
public void Animation_IDLE() {
animator.SetBool("isIDLE", true);
}
Then i want a specific moment on where all the animations should begin. For example a camera object will move around as shown in the example here. When the animation of the camera ends, the TriggerWakeUP() function is called, which then call the Animation_WakeUP().
public class DialogueTrigger1 : MonoBehaviour {
public Dialogue dialogue;
public GameObject playerPrefab;
public Animator playerAnimator;
public void TriggerWakeUP() {
FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
FindObjectOfType<Movements>().Animation_WakeUP();
}
}
As you can see from the provided link this will execute the animation as soon as the player is loaded. How to prevent this, so that i can call the beginning of animation at any point?
Do you really need the parameters? Can't you just get rid of the parameters and set an exit time ins$$anonymous$$d?
Answer by Tomashu · May 06, 2019 at 01:17 AM
The default state, the orange one, is the state the animator starts in when it is entered - in your case when it is created.
So you'll have to add another state that has an empty animation as the default state if you don't want it to do anything at all until isAwake is set.
Your answer
Follow this Question
Related Questions
Active camera on Start 1 Answer
Camera switching : C# onTriggerEnter not working 1 Answer
2D Style Camera, Shifting at Screen Edge 1 Answer
camera detect collision 2 Answers