All your GameObjects are being affected because they all use this script, therefore this code is ran in every GameObject. That is, that Update()
method is going to run once in every GameObject that has this script every update cycle.
The way you are making it run in only one or some GameObjects depends a lot on what you want to do. For example, what makes one given GameObject be the one that is supposed to run the code? You should add some logic to only allow the desired object to run Update()
, like this:
void Update() {
if(!hasToken)
return;
// ...
}
And you'd have another script that would pass the token to the right GameObject.