- Home /
Question by
GraviterX · Feb 17, 2014 at 03:59 AM ·
javascriptdestroy
Destroy gameobject
Hi all! I have a problem in a script I have. I used Destroy.gameObject with OnTriggerExit but it comes up with an error saying (Assets/Scripts/Random Messages/I see you.js(47,9): BCE0034: Expressions in statements must only be executed for their side-effects. ) How would I fix this? // Smothly open a door var smooth = 2.0; var DoorOpenAngle = 90.0; private var open : boolean; private var enter : boolean;
private var defaultRot : Vector3;
private var openRot : Vector3;
function Start(){
defaultRot = transform.eulerAngles;
openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
}
//Main function
function Update (){
if(open){
//Open door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
}else{
//Close door
transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
}
if(Input.GetKeyDown("o") && enter){
open = !open;
}
}
function OnGUI(){
if(enter){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "I see you");
}
}
//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "MainCamera") {
enter = true;
}
}
//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "MainCamera") {
enter = false;
Destroy.gameObject;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613133752im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Destroying assets is not permitted to avoid data loss.? 3 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
OnTriggerEnter to Destroy Objects not working Correctly 1 Answer