Hello guys. I need help with some animation and some scripting. I wan’t it to run my jump animation when i press space while running or walking. So if im running by pressing W and LeftShift and then wan’t to jump then while holding those buttons down i press space to jump. Then i jump but the animation don’t play because its running the other animations. It also happens if i walk and press space to jump. It don’t play the animation. Only when im standing still or being idle and press space. I would like if u guys could help me with it.
I guess what i need is some kind of a code that checks if im n the air or if im on the ground. Then i need it to say if im in the air it have to pause or stop the walk/run animation and then play the jump animation. Then when im on the ground i wan’t it to start the walk/run animation again. of cause if im idle it don’t have to play the walk and run animation
This is my script
#pragma strict
var TheDamage : int = 50;
var Distance : float;
var MaxDistance : float = 1.5;
var TheMace : Transform;
function Update ()
{
if (Input.GetButton("Fire1"))
{
//Attack animation
TheMace.animation.Play("Attack");
//Attack function
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
} //animation til bevægelse (At gå frem og tilbage med våbnet) og at hoppe.
if (Input.GetButtonUp("Fire1"))
{
TheMace.animation.CrossFade("Idle");
}
if (TheMace.animation.isPlaying == false)
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKey (KeyCode.W))
{
TheMace.animation.CrossFade("Walk");
if (Input.GetKey (KeyCode.LeftShift))
{
TheMace.animation.CrossFade("Sprint");
}
}
if (Input.GetKey (KeyCode.A))
{
TheMace.animation.CrossFade("Walk");
if (Input.GetKey (KeyCode.LeftShift))
{
TheMace.animation.CrossFade("Sprint");
}
}
if (Input.GetKey (KeyCode.S))
{
TheMace.animation.CrossFade("Walk");
if (Input.GetKey (KeyCode.LeftShift))
{
TheMace.animation.CrossFade("Sprint");
}
}
if (Input.GetKey (KeyCode.D))
{
TheMace.animation.CrossFade("Walk");
if (Input.GetKey (KeyCode.LeftShift))
{
TheMace.animation.CrossFade("Sprint");
}
}
if (Input.GetKeyUp (KeyCode.LeftShift))
{
TheMace.animation.CrossFade("Walk");
}
if (Input.GetKeyUp (KeyCode.W))
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKeyUp (KeyCode.S))
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKeyUp (KeyCode.A))
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKeyUp (KeyCode.D))
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKeyUp (KeyCode.Space))
{
TheMace.animation.CrossFade("Idle");
}
if (Input.GetKeyDown (KeyCode.Space))
{
TheMace.animation.CrossFade ("Jump");
}
}