I’m trying to make a lightsaber game and it’s looking pretty good but I’ve run into a problem. When I play the animation for my lightsaber attack (called “Attack” and “Attack2”) it won’t play the animation unless i hold down the mouse button. I want it to be to where i can click once and it plays the animation. I thinks the problem is i have a part in the script where it says if no button is being pushed, play the idle animation. How do I fix this problem?
Here’s my script:
var Rnd : int;
var anim : Animator;
function Update ()
{
if (Input.GetKeyDown(KeyCode.W))
{
anim.Play("Walk");
}
if (Input.GetKeyDown(KeyCode.A))
{
anim.Play("Walk");
}
if (Input.GetKeyDown(KeyCode.S))
{
anim.Play("Walk");
}
if (Input.GetKeyDown(KeyCode.D))
{
anim.Play("Walk");
}
if (Input.GetButtonDown ("Fire1"))
{
Attack();
}
if (Input.anyKey == false)
{
anim.Play("Idle");
}
}
function Start()
{
InvokeRepeating("Randomize",0,1);
}
function Randomize()
{
Rnd = Random.RandomRange(0,10);
}
function Attack()
{
if(Rnd < 5)
{
anim.Play("Attack");
}
else
{
anim.Play("Attack2");
}
}
Thanks in advance!