- Home /
Question by
Josenifftodd · Jan 13, 2014 at 04:40 AM ·
playermouseclickanimate
Problem getting my model to animate once mouse clicked
I have this script which lets me click the mouse and the player will go to wherever it is I have clicked. The problem I'm having is getting the player to animate so say I have a Ídle'and 'Walk' Animation, how would I get it to Animate when I click/hold the mouse key?
var speed : int;
private var targetPosition:Vector3;
function Update () {
if(Input.GetKey(KeyCode.Mouse0))
{
var playerPlane = new Plane(Vector3.up, transform.position );
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hitdist = 0.0;
if (playerPlane.Raycast (ray, hitdist)) {
var targetPoint = ray.GetPoint(hitdist);
targetPosition = ray.GetPoint(hitdist);
var targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = targetRotation;
}
}
transform.position = Vector3.Lerp (transform.position, targetPosition, Time.deltaTime * speed);
}
Comment