On an empty game object I have a spawn script that creates new enemies. On a character damage script, when the character dies it does:
BroadcastMessage(“Spawn”);
This is suppose to start my spawn function, but it does not, it says spawn has no reciever. Where am I going wrong and is there a better way than broadcast message?
BroadcastMessage does not broadcast to all game objects in the scene, but only to the children and the gameobject on which it is called. If you call BroadcastMessage by itself it is called on the same gameobject the calling script is attached to, thus your damaged character, not the empty game object.
You either need to put the script on your character objects or have a reference to the empty object in the damage script.
thanks, how can I reference the script in the gameobject then?
Create a variable inside it like var master : ScriptName; and drag the object holding the script that needs to hear the message onto the variable in the inspector.
it says, scriptname does not denote a valid file type?
In that example ScriptName was not to be used literally, but replaced with the script name you are trying to reference.
so what should i declare the var as so it shows up in the inspector?
Ok, so I have on my object that is destroyed:
var master : Transform;
Then my empty game object with my spawn script on is placed in this var.
But it still says that there is no receiver?