[help] My enemy cat is broken

Hello everyone I’ve made a cat on glitch garden that shoots sperm with is big ding dong :smile: but after some code changes it won’t work properly. In my first attempt the cat was moving with the animator like this : walk 2 times, shoot then walk again and after the fifth shoot the cat shoots a lethal sperm made by 3 sperms together (pls don’t judge me). It worked but when the cat entered the collider of the defender it continued to walk until the walk state finished so I decided to script everything and I used a box collider 2D private void OnTriggerEnter2D(Collider2D collider) and inside of it

{
        GameObject obj = collider.gameObject;
        if (!obj.GetComponent<Defenders>())
        {
            return;
        }
        Fire();
        IsWalking = false; 
    }

the fire method is this:

{
        animator.SetBool("IsAttacking", true);
        GameObject newProJectile = Instantiate(projectile) as GameObject;
        AudioSource.PlayClipAtPoint(audioClip, new Vector3(0, 0, 0));
        newProJectile.transform.parent = projectileParent.transform;
        newProJectile.transform.position = gun.transform.position;
        times++;
        if (times >= 5)
        {
            animator.SetBool("IsSuperAttacking", true); 
            GameObject newProJectile2 = Instantiate(projectile2) as GameObject;
            AudioSource.PlayClipAtPoint(audioClip, new Vector3(0, 0, 0));
            newProJectile2.transform.parent = projectileParent.transform;
            newProJectile2.transform.position = gun.transform.position;
            times=0;
        }
    }

the Super attacking bool is connected to the attacking state in the animator.
The problem is that the cat doesn’t stops while attacking an enemy like the other animals (even the one that I made all by myself after the course), but he is perpetually shooting while walking on the defender square, when he overcome the defender square he stops shooting.


image
I know that I should change the OnTriggerEnter2D method but I don’t know how. Could you please help me?

Privacy & Terms