Hi
Trying to get the animator controller to work and have added a roar animation for my monster. The animation is in the base layer and taps off the idle animation. I am using the Idle Run Jump script and have added a bool and tried to edit the script so it works but it doesnt. Also the Hi animation loops once activated, it just keeps going and going when it should be a one time animation. Is there a way to stop that?
Here is the script where I tried to add Roar to Fire3. Any help appreciated.
using UnityEngine;
using System.Collections;
public class IdleRunJump : MonoBehaviour {
protected Animator animator;
public float DirectionDampTime = .25f;
public bool ApplyGravity = true;
// Use this for initialization
void Start ()
{
animator = GetComponent<Animator>();
if(animator.layerCount >= 2)
animator.SetLayerWeight(1, 1);
}
// Update is called once per frame
void Update ()
{
if (animator)
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if (stateInfo.IsName("Base Layer.Run"))
{
if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);
}
else
{
animator.SetBool("Jump", false);
}
if(Input.GetButtonDown("Fire2") animator.layerCount >= 2)
{
animator.SetBool("Hi", !animator.GetBool("Hi"));
}
if(Input.GetButtonDown("Fire3"))
{
animator.SetBool("Roar", !animator.GetBool("Roar"));
}
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
animator.SetFloat("Speed", h*h+v*v);
animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
}
}
}