So I am basically working on a tactics turn-based strategy game where I want to play the “attack” animation state only once and have it automatically gracefully transition to the “neutral” animation state that I built once the “attack” animation state finishes playing.
if (tokens[0].Equals(“attack”))
{
gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().SetBool("attackLocked", false);
gameManager.pMana -= gameManager.units[Int32.Parse (tokens[1])].atkCost;
print ("attacker position x:" + gameManager.units[Int32.Parse (tokens[1])].transform.position.x);
print ("attacker position z:" + gameManager.units[Int32.Parse (tokens[1])].transform.position.z);
print ("attacked position x:" + targetTileX);
print ("attacked position z:" + targetTileZ);
print ("attacker animation state #:" + gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().GetInteger("mode_and_dir"));
//Use the values assigned to targetTileX and targetTileZ from TileScript.cs:
//Attack animation based on the position of the tile that is going to be attacked
if(gameManager.units[Int32.Parse (tokens[1])].transform.position.z > (targetTileZ*10)){
gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().SetInteger("mode_and_dir", 8);
}
else if(gameManager.units[Int32.Parse (tokens[1])].transform.position.z < (targetTileZ*10)){
gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().SetInteger("mode_and_dir", 9);
}
else if(gameManager.units[Int32.Parse (tokens[1])].transform.position.x > (targetTileX*10)){
gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().SetInteger("mode_and_dir", 10);
}
else if(gameManager.units[Int32.Parse (tokens[1])].transform.position.x < (targetTileX*10)){
gameManager.units[Int32.Parse (tokens[1])].GetComponent<Animator>().SetInteger("mode_and_dir", 11);
}
Once the integer “mode_and_dir” is set, the attack animation state then plays as soon as the value is passed into the variable. In this function, how do I let the animation finish playing afterwards, before I change the value of “mode_and_dir” again?