- Home /
object not spawning but no error message
im trying to get a gameobject to spawn using these 2 scripts
(my trigger script)
function Update () {
//if(Input.GetKeyDown(t)) ToggleTrigger();
}
function ToggleTrigger () {
if (collider.isTrigger == true) {
collider.isTrigger = false;
print("Close");
}
else{
collider.isTrigger = true;
print("Opened");
}
}
and
(my send message/spawn script)
var sendToObject: GameObject;
var correctObject: GameObject; //this is the only object we allow to trigger the event
var targetFunction: String; // the name of the function to call
var prefab: Transform;
function OnTriggerEnter (object : Collider) {
if(object == correctObject.collider)
sendToObject.SendMessage("targetFunction");
Instantiate (prefab, Vector3(0, 0, 0), Quaternion.identity);
}
function OnTriggerExit (object : Collider) {
if(object == correctObject.collider)
sendToObject.SendMessage("targetFunction");
}
my issue is that my game runs with no errors but my prefab is NOT spawned, ive checked http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html & http://unity3d.com/support/documentation/Manual/Instantiating%20Prefabs.html sections of unity for help and but to no real avail can any one help me?
Answer by Esa · Feb 09, 2012 at 07:05 AM
The thing is, you don't have braces around that if. It should do the Instantiate-method regardless of what hits it. Are you sure your colliders are set correctly for the trigger events to happen?
Answer by Esa · Feb 07, 2012 at 06:50 AM
I cannot see the targetFunction method anywhere. Try reading through this
i have read you link, but i don't understand how it is relevant to my script. i'm not trying to create a damage system but to spawn an object once the player passes into the trigger, are you telling me i need to re-work this part of my script?
if(object == correctObject.collider)
sendToObject.Send$$anonymous$$essage("targetFunction");
Instantiate (prefab, Vector3(0, 0, 0), Quaternion.identity);
}
Your answer
Follow this Question
Related Questions
Cannot instantiate gameobject 3 Answers
Referencing instantiated objects at runtime 2 Answers
Problem with Intantiate using uLink! 2 Answers
getting GameObject from Array and then instantiating 2 Answers
Reference by Instance ID? 2 Answers