I’m having a problem with a list that I’m creating for all waypoints near the player. The total number of teleporters in the first list is 7, but the second list prints higher than that and eventually the index goes out of range. I’ve been at this for a few hours trying to figure out what is going wrong, but I’m drawing a blank.
Any ideas? I’d greatly appreciate any assistance.
//Filling the teleporter list
Teleporters = GameObject.FindGameObjectsWithTag("Teleporter");
NumberOfTeleporters = Teleporters.Length;
//in a Get Button Down if statement
if (!Finding)
{
FindNear();
Finding = true;
}
//This is the function that is supposed to gather all teleporter waypoints and add the waypoints within distance parameters into a new list. It then sets a child object on
void FindNear()
{
for (int i = 0; i < NumberOfTeleporters; i++)
{
if (Vector3.Distance(CameraRig.transform.position, Teleporters*.transform.position) < MaxRange &&*
Vector3.Distance(CameraRig.transform.position, Teleporters*.transform.position) > MinRange)*
{
NearTeleporters.Add(Teleporters*);*
NearTeleporters*.GetComponent().Portal.SetActive(true);*
}
}
NumberOfNear = NearTeleporters.Count;
Clearing = false;
}
//In a get button up if statement
if (!Clearing)
{
NearClear();
Clearing = true;
}
//Function that clears the second list and sets all child objects in that list as inactive
void NearClear()
{
if (NearTeleporters[0] != null)
{
for (int i = 0; i < NearTeleporters.Count; i++)
{
NearTeleporters*.GetComponent().Portal.SetActive(false);*
}
NearTeleporters = new List();
NumberOfNear = NearTeleporters.Count;
}
Finding = false;
}