I tried making code so that if the character was in the air, it would play the “Jump Proj” (projectile) animation. I did this by having a boolean for “isInAir” to compare if touching the ground. But it never becomes true and “Proj Stand” animation seems to always be true and the boolean is always ignored. How can I write to boolean to be recognized?
private Animator anim;
private Rigidbody2D myBody;
bool isInAir;
void Awake () {
anim = GetComponent<Animator> ();
myBody = GetComponent<Rigidbody2D> ();
}
void Update ()
{
if (Input.GetKeyDown (KeyCode.JoystickButton1) && !isInAir)
{
Shoot();
AudioSource.PlayClipAtPoint (OrbFireSound, transform.position);
anim.SetBool ("Lexas Proj Stand", true);
Invoke ("SetBoolBack", 1f);
}
if (Input.GetKeyDown (KeyCode.JoystickButton1) && isInAir)
{
Shoot();
isInAir = true;
AudioSource.PlayClipAtPoint (OrbFireSound, transform.position);
anim.SetBool ("Lexas Jump Proj", true);
anim.SetBool ("Lexas Proj Stand", false);
Invoke ("SetBoolBack2", 1f);
}
}
void Shoot ()
{
// shooting logic
Instantiate(GreenOrbPrefab, firePoint.position, firePoint.rotation);
}
private void SetBoolBack ()
{
anim.SetBool ("Lexas Proj Stand", false);
}
// going to try to redo the boolean for jump here
void OnCollisionEnter2D(Collision2D other){
if (other.gameObject.CompareTag ("Ground")) {
isInAir = false;
myBody.velocity = Vector2.zero;
} else {
isInAir = true;
Debug.Log ("isInAir = true");
}
}
private void SetBoolBack2 ()
{
anim.SetBool ("Lexas Jump Proj", false);
}
}