0
votes

I imported a zombie character asset from the unity store and it came with one animator controller and two animation scripts. I already have my movement script attached to my zombie player and it moves when I press the arrow keys. I want it to do the run animation while it goes forward.

I added the animator component to my player and fed it with the animator controller which came with the asset. But when I click play I only see the idle standing animation and not the running one. do I need to use additional scripts?

2
Have the controller the condition for the backward button? like idle-(backward pressed)>runEl0din
the update method is empty, how you call the method run when the movements buttons are pressed?El0din
so how do i make it trigger the run animation when i press the move keys? using the update method?Mohit Saxena

2 Answers

0
votes

You need to call the methods in the Update method, something like this:

void Update() {
    if(Input.GetButtonDown("W")||Input.GetButtonDown("S")){
        Run();
    }else{
        OtherIdle();
    }
}
0
votes

Using input

You need to:
1. Detect input every frame (so in your Update() method).
2. Call the methodRun() to set the animation bool to true.

This will make the Run animation play when the "w" key is pressed if the Animator Controller is set up properly:

void Update () {

    // If the forward key is pressed...
    if (Input.GetKeyDown("w")){

        // Play the Run animation
        Run();
    }
}

Using speed

Alternatively you could give a new parameter to your animation controller "speed" and set the bool for the animation to play when speed is above a certain value. Else if the speed is below the value, play the Idle animation. This way, if you have a Walk animation, you can play it when the speed is between running speed and stationary.