I want to change a variable in a script which is in multiple gameobjects, I tried to use public GameObject enemy; and in the update I had enemy = GameObject.FindGameObjectsWithTag("Enemy"); but that won't work, how do I select every gameobject with tag "Enemy" and change a variable in all of their scripts?
asked Sep 26 '10 at 04:34 AM
You're on the right track.
You should probably do it less often than in every Update(), but FindGameObjectsWithTag will work. You then need to get the component (script) that the variable is in, using GetComponent, and then you can set it.
You just need to make sure that the variable you're declaring on those objects is publicly accessible (i.e. not in a function, and declared as public)
answered Sep 26 '10 at 07:24 AM
Instead of using
answered Sep 26 '10 at 06:58 AM