How do make a script only affect one game object.

I am working on a game where animals run around looking for food. I have a series of scripts using static variables to communicate with box colliders and the animal itself, telling it when it has collided with food and where to look for food next. The issue I have is that I instantiated 50 of these animals and whenever one of them runs into a piece of food, not only does it stop to look for more food but every animal stops to look for more food. Basically whenever one of them does something, the rest of them do it as well. They are all the same instantiated prefab so I am sure that has something to do with it but I am not exactly sure what is wrong. How do I make sure that each of their scripts effects them only and not the rest?  Thank you for your help!

  • Jonathan Gonzalez(jgonzalez) replied

    Sounds like the issue might be related to your static variables. Not sure how those are being used, but if you had a static variable to detect when the animal should stop looking for food, then that variable will be the same for everyone. For example, if I had a health script and the health variable was static. Every object that has that script will have the exact same health. If I killed one enemy that had that script, then all enemies who had it would also die. In general, static variables should be used only when it needs to be a single global variable in your game.