- Home /
Detect multiple collisions and assigning them to an array?
I have an object in the scene with a collider that detects for other colliders. Every time any number of with a specific tag enters the big collider I want the script to store it inside an array for further purposes.
This is all I have:
function OnTriggerEnter (Col : Collider) {
if(Col.CompareTag("Ingredients"))
{
//detects # of collisions here and assign them to an array?
}
}
I don't know what to do from here so any help is really appreciated. Thanks.
Use a List of whatever it is you want to store and then add those objects to your list using the list Add method. You would then access it through the index as you would an array, or use one of the several other helpful methods available to a list.
public List<GameObject> myList = new List<GameObject>();
//Add to the list
myList.Add(objectToAdd);
Your answer
Follow this Question
Related Questions
How to I add a collision's GameObject to an array? 2 Answers
Detecting if object in array collides with another object in same array 1 Answer
setting a transform var to an object that collided 1 Answer
Ignore Colliders of an Object 1 Answer
How do you execute Trigger-collider collision only in one gameobject? 1 Answer