bool not working on another cloned enemy
i made an enemy and i put a script c# with a bool inside and everything works fine, after i wanted to duplicate the enemy and everything is fine without errors but when i activate the bool only the original bool activates the clone doesnt activate! help please
You can make the boolean, static if you always want the same value across all instances of a script. You could similarly look at finding or creating a Singleton class to use.
Answer by alijaj · May 01, 2016 at 12:51 AM
@Mavina sorry for my bad english, my clone is a duplicate enemy ,and yes the original enemy has a follow bool inside that is false and when i run the game and i go in collision with a obstacle i see the bool going true and my script car calls the enemy bool to start following me and the enemy start following my player, the duplicated enemy instead remain false, i dont know how to do the same thing with the duplicated enemies(i mean they are same as the original).
So far this is what I can gather, please correct me if anything is inccorect
You have two GameObject's and each have an Enemy script attached (Lets call them Enemy_1 and Enemy_2).
Each Enemy GameObject has a Collider attached
The Enemy script has a bool variable named follow that defaults to false
Now when Enemy_1 collides with an obsticle you have an OnTriggerEnter() that sets the bool variable follow is to true (you state this works fine)
Now here is where I am losing you
and my script car calls the enemy bool to start following me and the enemy start following my player, the duplicated enemy ins$$anonymous$$d remain false
The only way that the follow variable in Enemy_2 can be set to true is if it collides with an obsticle or you set up some other type of method to do this
Do you have any script that you can share?
in the enemy gameobject i have the enemyscript controller where is the bool follow false inside.
i call this enemy bool to true from my other gameobject player which i control to play the game when the player collides with an obstacle.
in my playercontroll i access the enemy bool script like this public enemyscriptname boolfollow; here i assign the script or the car gameobject
void Oncoll.... { boolfollow.follow=true; //and the enemy follows me, but when i duplicate it the duplicated enemy doesnt respond to my call }
Is your OnCollisionEnter inside of the player script? If so then OnCollisionEnter() should look something like this
void OnCollisionEnter(Collision coll)
{
if ((coll.gameObject.tag == "Enemy") && (coll.gameObject.GetComponent<Enemy>() != null))
{
coll.gameObject.GetComponent<Enemy>().follow = true;
}
}
And I am not following you where you say "assign the script or the car gameobject". Also, what is boolfollow (boolfollow.follow=true)? Is boolfollow an enemy class in your player? If so boolfollow is only one enemy, you have two.
I am sorry but that tiny one line piece of script is not enough to go on. So far the best thing that I can answer you with is the OnCollisionEnter() script I posted above. I suggest that you post both your player control and your enemy script if you need any more help. This board can not provide answers to questions about script if we do not know what it looks like.
Your answer
![](https://koobas.hobune.stream/wayback/20220612075913im_/https://answers.unity.com/themes/thub/images/avi.jpg)