Saturday, April 25, 2015

c# - Control animation using animator control class



I did a sample existing code to control animation using animation.I dragged and dropped a character into the scene then I added a Animator to it and added the animator controller.Below I have given the screen short of the animation enter image description here


Then I have attached the following code to it


Animator animator;

int eatHash=Animator.StringToHash("ideal");

int stateHash=Animator.StringToHash("Base Layer.pickbothfork");

void Start () {
animator = GetComponent();

}

// Update is called once per frame
void Update () {
//animator.SetBool ("isEat", true);
float move = Input.GetAxis ("Vertical");
animator.SetFloat ("Speed",move);

AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo (0);
if (Input.GetKeyDown(KeyCode.Space))

{
Debug.Log ("clicked spacebar");
animator.SetTrigger(eatHash);
}
}

The problem here is the above code is working,when I run the project the animation is getting played one after the another according to the state diagram.But when I click on the space bar the trigger function(jump animation ) is not working


if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log ("clicked spacebar");

animator.SetTrigger(eatHash);
}

Can anybody please help me finding solution for it




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...