- Home /
Walk Animations?
This is the code for my point and click game, idle works but no run!: using UnityEngine; using System.Collections;
public class Clicktomove : MonoBehaviour { NavMeshAgent navAgent; Animation PlayerAnimation;
// Use this for initialization
void Start ()
{
navAgent = GetComponent<NavMeshAgent> ();
PlayerAnimation = GetComponent<Animation> ();
}
// Update is called once per frame
void Update ()
{
MovementAnimation ();
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if(Input.GetMouseButtonUp(0))
{
if(Physics.Raycast(ray, out hit, 1000))
{
navAgent.SetDestination(hit.point);
}
}
}
void MovementAnimation(){
//print (navAgent.velocity);
if (navAgent.velocity.x != 0 || navAgent.velocity.y != 0 || navAgent.velocity.z != 0) {
if
(!PlayerAnimation.isPlaying){
PlayerAnimation.CrossFade ("run");
PlayerAnimation.Play("run");
}
print ("Moving!");
} else {
if (!PlayerAnimation.isPlaying){
PlayerAnimation.CrossFade ("Idle");
PlayerAnimation.Play("Idle");
}
print ("Not moving!");
}
}
}
Comment
Your answer