- Home /
How to have multiple animations (Walk, run, idle)?
I have four animations; idle, walk, run and grab.
I want to attach each to there own key (walk = "W" and so on), but my code does not work when I run the game.
When I play the game, the model only does the grabbing animation.
When I made these in maya, i did a separate model for each animation, but i do not think that is the problem. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMoveScript : MonoBehaviour
{
Animator anim;
int GrabHash = Animator.StringToHash("Grab");
int WalkHash = Animator.StringToHash("Walk");
int RunHash = Animator.StringToHash("Run");
void Start ()
{
anim = GetComponent<Animator>();
}
void Update ()
{
// float move = Input.GetAxis ("Vertical");
//anim.SetFloat("Speed", move);
// AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
if(Input.GetKeyDown(KeyCode.E))
{
anim.SetTrigger (WalkHash);
}
else if(Input.GetKeyDown(KeyCode.W))
{
anim.SetTrigger (RunHash);
}
else if(Input.GetKeyDown(KeyCode.G))
{
anim.SetTrigger (GrabHash);
}
}
}
screenshot-14.png
(492.1 kB)
Comment