How to play animation
Hi i m a new user of unity and after reading a lot of doc (the most are to old ... shame on me) i can't find how to animated my character .
How to play my animation "run" when i m moving and how to play my "idle" animation when i m not
Ty.
Sorry for my bad english ^^
using UnityEngine; using System.Collections;
public class ClickToMove : MonoBehaviour { public float speed; public CharacterController controller; private Vector3 position;
// Use this for initialization void Start () { position = transform.position; anim = GetComponent(); }
// Update is called once per frame void Update () { if(Input.GetMouseButton(0)) { //Localiser ou on cliquer sur la map locatePosition(); } // Deplacer à la position ciblé moveToPostition(); } void locatePosition() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 1000)) { position = new Vector3(hit.point.x, hit.point.y, hit.point.z); Debug.Log(position); } } void moveToPostition() { if (Vector3.Distance(transform.position, position) > 1) { Quaternion newRotation = Quaternion.LookRotation(position - transform.position); newRotation.x = 0f; newRotation.z = 0f; transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime 10); controller.SimpleMove(transform.forward speed);
}
else
{
}
} }
I will put a screen of my screenplay maybe it will helped.
Thx guys.