Last active
December 10, 2018 22:01
-
-
Save aomnes/79f92c46c4532d57de31ab3aafd4be70 to your computer and use it in GitHub Desktop.
unity get list on trigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Has to go at the top of your file | |
#pragma strict | |
import System.Collections.Generic; | |
//The list of colliders currently inside the trigger | |
var TriggerList : List.<Collider> = new List.<Collider>(); | |
//called when something enters the trigger | |
function OnTriggerEnter(other : Collider) | |
{ | |
//if the object is not already in the list | |
if(!TriggerList.Contains(other)) | |
{ | |
//add the object to the list | |
TriggerList.Add(Other); | |
} | |
} | |
//called when something exits the trigger | |
function OnTriggerExit(other : Collider) | |
{ | |
//if the object is in the list | |
if(TriggerList.Contains(other)) | |
{ | |
//remove it from the list | |
TriggerList.Remove(Other); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment