- Home /
Question by
UltraQuality · Mar 28, 2014 at 06:10 PM ·
animation
Player is running just few seconds
The player is running just few seconds,How can i fix it? This is my player running code: using UnityEngine; using System.Collections;
public class Running : MonoBehaviour
{
public Animator animator;
public float rotSpeed = 90f;
public bool canRun = true;
public float r;
void Start ()
{
animator = GetComponent<Animator>();
}
void Update ()
{
}
void FixedUpdate()
{
float h = Input.GetAxis ("Horizontal");
float v = Input.GetAxis ("Vertical");
r = Input.GetAxis ("Run");
animator.SetFloat ("V Input", v);
animator.SetFloat ("Turning", h);
transform.Rotate(new Vector3(0, h * Time.deltaTime * rotSpeed, 0));
StartCoroutine (ProcessRun ());
}
IEnumerator ProcessRun()
{
if (r == 1 && canRun == true)
{
animator.SetBool ("Running", true);
yield return new WaitForSeconds(0);
animator.SetBool ("Running", false);
canRun = false;
print (canRun);
}
else if (r == 0)
{
yield return new WaitForSeconds(0);
canRun = true;
}
}
}
Comment