- Home /
Problem with Animator
I have made a prefab for my enemy. And i m using it for object pool. Problem is that when i hit any enemy with fire then i have made OnTrigger Function for playing a destroy animation from animator by setting a bool to true but Animation plays on all of the objects.But if i drag prefabs to hierarchy 3 -4 times then animations plays correctly on the hitted enemy.?
Answer by Camilohoyos16 · Aug 16, 2017 at 05:26 PM
I don't how you are calling the trigger on objects, but maybe you are change bool variable on the prefab script, so, the others copies, change with the prefab. I mean, try to keep a refenrence for each copy of prefab you instantiate and make the change of variable in taht gameobject.
Answer by sajid00002 · Aug 17, 2017 at 01:11 PM
@Camilohoyos16 yes i am changing bool on prefab script how can i keep the reference to each copies?
You can create an array or a list, if you don't know how many prefab you'll instantiate, in a gameobject that can survive during the time you need the references of that gameobjects. If you don't how to know wich gameobject is being hit, you can get the name fo that gameobject, prefab copy(some number), so you can go to the list and search easier the gameobject. Or you can create a variable in some attach script in those gameobjects and assign an index, when you hit that gameobject go to search for that index in the list and find respective gameobject
Your answer
Follow this Question
Related Questions
Mac standalone doesn't open 0 Answers
Android back button not working 2 Answers
Network functions doesn't work 0 Answers
unity won't start? 3 Answers
Why wont my follow scripts work? 1 Answer