I have a script that is attached to a prefab, this prefab is spawned in the game world 10 times. The script tells the objects to choose a target with the tag 'Stone' and there are about 400 stones in the world. The thing is, they all choose the exact same stone, how do I make them truly choose a random one?
asked Apr 19 '11 at 09:57 AM
Read through the documentation for both, and if you're still having trouble, let me know and I'll update my answer with further details.
Actually just calling you variable "RandomTarget" doesn't make your target random at all! :D
When you call FindWithTag function you get just the first element with that tag (I fought with that function just this morning! :D)
You should first get the whole array of GameObjects with the wanted tag, like this...
And then for every object which must point to one of those you can choose a random target...
That should do the trick! :)
answered Apr 19 '11 at 10:24 AM