Hello,
I have been using Unity about a week now and have managed to get the character running and in an idle state. I have further tried to add an aim animation which works but only when the added run and idle animations are disabled. Please can you help me?
#pragma strict
var speed = 3.0;
var rotateSpeed = 3.0;
function Start () {
// Set all animations to loop
animation.wrapMode = WrapMode.Loop;
// except shooting
animation["shoot"].wrapMode = WrapMode.Once;
// Put idle and walk into lower layers (The default layer is always 0)
// This will do two things
// - Since shoot and idle/walk are in different layers they will not affect
// each other's playback when calling CrossFade.
// - Since shoot is in a higher layer, the animation will replace idle/walk
// animations when faded in.
animation["shoot"].layer = 1;
// Stop animations that are already playing
//(In case user forgot to disable play automatically)
animation.Stop();
}
function Update ()
{
// This var is using the CharacterController on your model
var controller : CharacterController = GetComponent (CharacterController);
//Rotate around y -axis
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//move forward / backwords Vertical
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
animation.CrossFade ("run");
else
animation.CrossFade ("idle");
if (Input.GetButtonDown("Fire1"))
animation.CrossFade("shoot");
}
@script RequireComponent(CharacterController)