Why does my script destroy all objects with the script
I am making a script that tells instructions on the screen, then destroy the trigger, but the script destroys every trigger with the script. here it is C#
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Instructions : MonoBehaviour {
public Text text;
public string instruction;
public GameObject trigger;
void OnTriggerEnter(Collider Other){
text.text = (instruction);
Time.timeScale = 0;
}
void Update(){
if (Input.GetKey (KeyCode.Tab)) {
Time.timeScale = 1;
**DestroyObject (trigger);**
text.enabled = false;
}
}
}
What's your Hierarchy looks like? How do you initialize trigger
GameObject?
How do you mean how do I initialize Trigger Edit: I actually have it to where I have a variable with each game object in their own for each trigger. So trigger 1 has trigger one that will be destroyed
Answer by Baste · Sep 04, 2015 at 05:51 PM
You destroy the gameObject if tab is pressed. So whatever you have put in the trigger slot on every single instance of this script will be destroyed when tab is presed.
Also don't use DestroyObject, use Destroy. DestroyObject is deprecated and undocumented.
Your answer

Follow this Question
Related Questions
Why is this not working? 1 Answer
Enemy destroys player if scale is bigger 1 Answer
Saving data in a txt file from Input Field button? 0 Answers
A namespace can only contain types and namespace declarations..(39,14) 0 Answers
unity c# money system 2 Answers