Skip to content

Instantly share code, notes, and snippets.

@aomnes
Last active December 10, 2018 22:01
Show Gist options
  • Save aomnes/79f92c46c4532d57de31ab3aafd4be70 to your computer and use it in GitHub Desktop.
Save aomnes/79f92c46c4532d57de31ab3aafd4be70 to your computer and use it in GitHub Desktop.
unity get list on trigger
//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