Hi! I have a GameObject function in a Start() with the purpose of finding an object with a specific tag which is closest to the object which the script is referenced to. This is the Start() code from the script. Everything before “FindClosestIntersectionTarget” method is correctly executed; everything after it is like they don’t exist :
private void Start()
{
Player1 = GameObject.FindGameObjectWithTag("Player1");
Player2 = GameObject.FindGameObjectWithTag("Player2");
Player3 = GameObject.FindGameObjectWithTag("Player3");
Player4 = GameObject.FindGameObjectWithTag("Player4");
Arrow = GetComponent<Animator>();
FindClosestIntersectionTarget(currentPathArrowManagerEgypt);
pathArrowScript = currentPathArrowManagerEgypt.GetComponent<PathArrowManagerEgypt>();
gameControllerObj = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
switch (pathArrowScript.playerinIntersection)
{
case 1:
SelectedPlayer = Player1;
break;
case 2:
SelectedPlayer = Player2;
break;
case 3:
SelectedPlayer = Player3;
break;
case 4:
SelectedPlayer = Player4;
break;
}
}
This is the code inside “FindClosestIntersectionTarget()” method:
GameObject FindClosestIntersectionTarget(GameObject currentPathArrowManagerEgypt)
{
Vector3 arrowPosition = transform.position;
return GameObject.FindGameObjectsWithTag("PathArrowEgypt1")
.OrderBy(o => (o.transform.position - arrowPosition).sqrMagnitude)
.FirstOrDefault();
}
As you can see, nothing special. There is something about GameObject functions which I’m overlooking?