I have a model and I already have the walk and Idle animation to play but somehow I can never get the “Jump” to play. I really can’t figure why?
I used tried triggers but still no good.
here is my code on my model called “AnimatePlayer”:
#pragma strict
var body : Transform; //Tranform the armature of the player model
var mousexThreshold = 0.2; //Number of units for the mouse to move on x-axis
//Settings for the Upper Body rotation
var sensitivityY = 15F;
var minimumY = -60F;
var maximumY = 60F;
var rotationY = 0F;
var jumpBool : boolean;
function Start()
{
//set animation Wrap Mode for the attack to "Once"
animation["Jump"].wrapMode = WrapMode.Once;
}
function Update () {
if( transform.rotation.eulerAngles.y == 270 ) { // Left rotation
if(Input.GetAxis("Horizontal") > 0) //Walk Backwards
{
animation["Walk"].speed = -2;
animation.Play("Walk");
}
else if(Input.GetAxis("Horizontal") < 0) //Walk Forward
{
animation["Walk"].speed = 2;
animation.Play("Walk");
}
else if(Input.GetAxis("Horizontal") == 0)
{
animation.Play("Idle");
}
}
if( transform.rotation.eulerAngles.y == 90.00001 ) { // Right rotation
if(Input.GetAxis("Horizontal") > 0) //Walk Forward
{
animation["Walk"].speed = 2;
animation.Play("Walk");
}
else if(Input.GetAxis("Horizontal") < 0) //Walk Backwards
{
animation["Walk"].speed = -2;
animation.Play("Walk");
}
else if(Input.GetAxis("Horizontal") == 0) //Return to standing posture
{
animation.Play("Idle");
}
}
// Transform the rotation of the player when mouse moves on the x-axis
var mousex : float = Input.GetAxis ("Mouse X");
if (mousex > mousexThreshold) //Player faces right
{
transform.forward = new Vector3(1f, 0f, 0f);
}
else if (mousex < -mousexThreshold) //Player faces left
{
transform.forward = new Vector3(-1f, 0f, 0f);
}
}
function LateUpdate(){
// will make the upper body of the model to be rotatable along the y-axis
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
body.transform.localEulerAngles = new Vector3(0, rotationY, 0);
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Ground"){
animation.Play("Jump");
}else if(other.tag == "Platform"){
animation.Play("Jump");
}
}
function OnTriggerExit(other : Collider){
if(other.tag == "Ground"){
animation.Play("Idle");
}else if(other.tag == "Platform"){
animation.Play("Idle");
}
}
As you can see, I have a trigger to play the “Jump” animation but still nothing. Is it because I have a lot of animations playing all at once?