- Home /
The question is answered, right answer was accepted
Destroying Multiple Game Objects w/ OnTriggerEnter
I am trying to create a script that will destroy three separate game objects in my scene when the (standard asset) FPSController enters the trigger it is placed on. I have been trying to write this in Js because I would like to assign both the FPSController name and the game object name(s) in the inspector instead of the code.
Below I have created a pseudo code of what I think the code will look like:
 var (name of the FPSController)
 var (Object1 that will get destroyed)
 var (Object2 that will get destroyed)
 var (Object3 that will get destroyed)
 
 function (OnTriggerEnter script)
         If Collider == (name of FPSController)
                Destroy (Object1)
                Destroy (Object2)
                Destroy (Object3)
Any help is appreciated, I am new to coding and keep getting errors in anything I produce for this solution.
Answer by Namey5 · Oct 30, 2016 at 05:19 AM
FYI; you can assign things in the inspector in both languages, it isn't something limited to JS. You would do this pretty much how you have written it;
 public var controller : GameObject;
 public var object1 : GameObject;
 public var object2 : GameObject;
 public var object3 : GameObject;
 
 function OnTriggerEnter (col : Collider)
 {
     if (col.transform.gameObject == controller) {
         Destroy (object1);
         Destroy (object2);
         Destroy (object3);
     }
 }
I have read that static variables cannot be edited in the inspector when written in C#, and in my experience this seemed correct as I hadn't been able to get them to show up in the inspector in the past. I must have been missing something.
Thank you so much, the script works perfectly. $$anonymous$$uch appreciated!
You're right - static variables can't be edited in the inspector. But none of those variables are static.
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                