I build a fighting game. There are Player and NPC.
When Player moves close to NPC, NPC starts to fight.
There are 3 fight animations:
punch
kick
special
Here is the code:
var incre : int = 0;
var ran : int[];
ran = new int[3];
function Update ()
{
var heading = targetTransform.position - transform.position;
if(heading.x > -2 heading.x < 2)
{
if(ran[incre] == 0)
{
Punch();
incre += 1;
}
if(ran[incre] == 1)
{
Kick();
incre += 1;
}
if(ran[incre] == 2)
{
Special();
incre += 1;
}
if(incre == 2)
{
incre = 0;
}
}
}
However, it always plays Punch() only.
I think the logic for
if(incre == 2)
{
incre = 0;
}
is wrong.
As each time of update, incre resets to 0.
How should I change the logic?
to play punch, kick and special sequence?