- Home /
Question by
rick-grendel · Feb 28, 2015 at 04:09 PM ·
javascriptdestroy
Script destroys all gameobjects with script.
Hello I have a script this script must destroy a object when the player is in the triggerzone and press e. but if the player is in the trigger zone and presses e all the objects disappear. instead of the only objects the player is in. Here is the script:
#pragma strict
var Enter: boolean;
var ItemID: String;
var ItemName: String;
var Stone: GameObject;
var Player: GameObject;
var Controller: GameObject;
var Items: Items;
function Start () {
Items = Controller.GetComponent("Items");
Stone = GameObject.Find("triggerStone0");
}
function Update () {
if(Enter && Input.GetKey("e")) {
Debug.Log("Just picked up item: " + ItemName + " " + "ItemID: " + ItemID);
Destroy(Stone);
}
}
function OnTriggerEnter (col : Collider) {
if(col.collider.tag == Player.tag) {
Enter = true;
}
}
function OnTriggerExit (col : Collider) {
if(col.collider.tag == Player.tag) {
Enter = false;
}
}
Comment
Answer by SuperMasterBlasterLaser · Feb 28, 2015 at 04:49 PM
Maybe you need to use GetKeyUp method unstead of GetKey
Your answer
![](https://koobas.hobune.stream/wayback/20220613184612im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to Disable/Enable another Script with Triggers? 1 Answer
destroy gameObject when in range? 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Destroy and Spawn an Enemy 1 Answer