- Home /
Calling a function from a instantiated clone
So I'm making a FPS, and when I shoot the enemy, a new one respawns. So the enemy, in a prefab. Once I shoot him I'm trying to send a message to that instantiated clone, but it doesn't work. But if don't use Instantiate, it works, but the thing is that I need more than 1 enemies. It seems that .SendMessage doesn't work for instantiated prefabs? :S
help any1?
Also I'm not new to scripting...
I forgot to say the i'm trying to send "kill" so that the enemy disapears.
and this is the function: function kill(){ Destroy(gameObject, 1); }
Answer by DaveA · Jul 16, 2012 at 08:33 PM
You should post your code (remember to format it) but my guess is, you are not saving the game object that is created by Instantiate. If you do, you can use that as the basis of the SendMessage, eg:
var enemy;
... later ....
enemy = Instantiate (enemyPrefab, ......
... later ...
enemy.SendMessage ("kill");
Your answer
Follow this Question
Related Questions
Instantiated Prefab's script doesn't work 2 Answers
How to access script variables attached to a prefab at runtime in Javascript? 2 Answers
Instantiating Prefab from Javascript - BCE0005: Unknown identifier: 'Prefab' 2 Answers
[Solved]Instantiating prefab from a script and destroy it from another one 2 Answers
Network instantiate command do not execute in all client.. 1 Answer