|
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?
(comments are locked)
|
|
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)
(comments are locked)
|
|
Instead of using That won't work. Using static will make a single, game-wide variable. He's asking to change a variable in multiple GameObjects. Unless he actually needs them all to be the same value, he'll need a public variable in each.
Sep 26 '10 at 07:26 AM
Marowi
Oh, sorry; guess I interpreted it incorrectly.
Sep 26 '10 at 07:34 AM
PeterDC
that was actually what I wanted... I wanted to change the health of all of the enemies. thanks for the help.
Sep 26 '10 at 08:39 AM
MonkeyAssassin8
(comments are locked)
|
