A gameObject copy does not work like the original gameObject

first of all Sorry if the text is wrong, I used Google Translate.

I am making a 2D game in Unity. I made an enemy that is always moving between 2 points, and if the player is exposed to this enemy, the enemy stops walking (which means the walking animation is disabled) and starts hitting the player (Attack animation is activated) and if the player goes out of sight it will continue to move again. All these steps are done correctly. The problem starts when I create a copy of the enemy to put it in another place, all the scripts work for the copied object, but its animations are problematic. For example, when the player is exposed to him, he stops moving, but the walking animation is still running and the attack animation is not performed. But for example, when I hit him, the hurt animation is run, then he attacks twice, and walk animation run again without the player being out of his sight , while none of this makes sense. I emphasize that the only problem is that the animations are not executed at the right time, otherwise all other parts of the code for the copy object will work.

void Update() 
{
    coolDownTimer += Time.deltaTime;
    if (EnemySeePlayer())
    {
        enemySelf.GetComponent<enemyWalk>().enabled = false;
        anime.SetBool("isWalk",false);
        if (coolDownTimer >= attckCooldwon)
        {
            coolDownTimer = 0;
            anime.SetTrigger("isAttack");
            Debug.Log("see");
            //DamagePlayer();
        }
    }
}

This is the script I wrote for the enemy to attack the player.

coolDownTimer is a variable so that the enemy cannot hit the player rapidly.

EnemySeePlayer is a function that determines whether the player is visible to the enemy or not.

In the first line of function , enemy’s walk script will be disabled if the condition is met. that this part works correctly.

But in the second line, (anime) which is a variable that contains the enemy’s animator, sets the value of the isWalk parameter to false so that the enemy’s walking animation is disabled and goes to idle animation. The first problem is because this part works for the original version of the enemy, but not for its copies.

This problem exists exactly for the isAttack parameter and it is not executed either.

I put a Debug.Log to find out if the conditions are executed for the copies, and I found out that the code works correctly and the problem is only the animator part.

I even used prefab but it didn’t work. I used the clone method and it worked but I’m looking for a way that doesn’t require coding.

hey, I think this happens because you use a bool parameter to manage walk animation. Use a float as a horizontal movement and compare it to zero. if it’s negative go left, if positive go right. you can use a blend tree too.:cherry_blossom::v:t3: