- Home /
Question by
Skyline Studios · Sep 28, 2012 at 04:42 PM ·
triggerobjectdeleteon
On Trigger Delete Object
function OnTriggerEnter (other : Collider) {
Destroy(gameObject.Ghostmodel);}
Hi I Wrote This Script To Delete A Ghost When I Look Through A Door. To Look Through The Door I Had To Enter A Trigger Zone But It Doesn't Delete My Ghost. Help Would Be Appreciated
Comment
Best Answer
Answer by fafase · Sep 28, 2012 at 04:49 PM
I would guess you have forgotten to have a look at the documentation.
var ghost :GameObject; // Declare a variable of type game object
function Start(){
ghost = GameObject.Find("Ghost"); // get a reference to the ghost object and assign it to the ghost variable.
//Now using ghost onthis script is using the original ghost object.
}
function OnTriggerEnter (other : Collider) {
//Check who collides using the other variable which is a reference to the object colliding (confusing I know...)
if(other.gameObject.tag == "Player")
// Destroy the ghost object, trying to access the ghost will result in a null reference, it is gone.
Destroy(ghost);
}
Thanks This Really Helped $$anonymous$$e Out!. (And Yeh I Forgot To Look At Documentation XD)
thanks so much i had a similar problem and it has fixt it thank you
Your answer
Follow this Question
Related Questions
How to call a function from a script component on another object 1 Answer
Keep an object on the gound. 2 Answers
2D game object trigger 1 Answer
Spawning an object with entering a trigger. 0 Answers
Object Sound Trigger 1 Answer