Gameobject list does not retrieve the first index in for loop
So i'm trying to create a hovering object above a building to show they've selected the building and can edit whatever is in it. But once i start looping over the List with GameObjects it fails since it skips over the first index and goes straight to the second index.
But the code does function normally on the second index on the list
private void CheckForHoverOnBuilding()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
for (int i = 0; i < _BuildingList.Count; i++)
{
if (hit.collider.gameObject == _BuildingList[i])
{
obj = _BuildingList[i].gameObject;
SelectBuilding();
}
else
{
obj = null;
ResetHighligher();
}
}
}
}
Can't see any reason why the first index of the list would be ignored. Try adding some logs into the code to check which object and index is being processed on each iteration to confirm exactly what is happening, Let us know what you find and it might help.
Your answer
Follow this Question
Related Questions
assign objects to strings from SQLite table 0 Answers
Getting objects out of a list and then comparing them 0 Answers
How to delete an object if there is another object of the same type at that position ? 1 Answer
Help with checking if gameobjects are the same on diagonal 1 Answer
For Loop: Different count of objects are added to lists 0 Answers