x


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?

more ▼

asked Feb 06 '12 at 08:33 PM

Greatalastor gravatar image

Greatalastor
1 5 8 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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?

more ▼

answered Feb 09 '12 at 07:05 AM

Esa gravatar image

Esa
273 1 3 7

(comments are locked)
10|3000 characters needed characters left

I cannot see the targetFunction method anywhere. Try reading through this

more ▼

answered Feb 07 '12 at 06:50 AM

Esa gravatar image

Esa
273 1 3 7

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.SendMessage("targetFunction");

   Instantiate (prefab, Vector3(0, 0, 0), Quaternion.identity);

}

Feb 07 '12 at 04:23 PM Greatalastor
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2170
x1725
x1121
x453
x1

asked: Feb 06 '12 at 08:33 PM

Seen: 541 times

Last Updated: Feb 09 '12 at 07:05 AM