Get index of object in a list that's detected by raycast?

Hi guys,

I have a list, lets just say “spawnedObjectList” and a GameObject is added to this list when instantiated. I then have a script that detects the object detected from a raycast.

So lets say 2 objects are instantiated and added to the “spawnedObjectList”, and the raycast detects the gameobject from index 1… anyone know how I can get the index for this game object in the “spawnedObjectList” it is in and store the index in an int?

Thanks!

C# Lists have a GetIndexOf() function that returns an integer to that items place in the list.

2 Likes

Perfect!