- Home /
how to destroy an object permanently ?
i have a gate that asks question before you will be able to enter. if you clicked the correct answer, the gate must be destroyed. My problem is that, after i answered the question correctly, the gate object will be destroyed and my character will pass to the other side but when i move back to where the gate object was, the collision is still there and it would ask me again? do you know how to resolve this? here is my code:
var showGUI = false;
var isopen : boolean;
var launcherUpgrade1 : Texture2D;
function Start ()
{
transform.collider.isTrigger = true;
renderer.enabled = true;
}
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "TIGER" )
{
transform.collider.isTrigger = false;
showGUI = true;
}
if(showGUI == false)
{
transform.collider.isTrigger = false;
renderer.enabled = false;
showGUI= false;
}
}
function OnGUI () {
if (showGUI) {
GUI.Box (Rect (10,10,500,200), "Question 1: blah blah blah blah");
if (GUI.Button (Rect (20,40,80,20), "a. 1611")) // thsi is the correct answer
{
transform.collider.isTrigger = true;
renderer.enabled = false;
showGUI=false;
isopen = false;
}
else if(GUI.Button (Rect (20,60,80,20), "b. 1711"))
{
transform.collider.isTrigger = false;
isopen =false;
}
}
}
Please edit your post...
Get all the code inside the CODE tags, and please remove the extra lines.
Answer by Berenger · Jan 28, 2012 at 02:55 PM
You need to use Destroy( gameObject ) if you want all the object to be destroyed, or Destroy( collider ) for just the specific component.
You don't need, by the way, to use transform.collider, you can access collider directly, it's a Component property.