Hello, i have this issue where an array wont store any GameObject element. As you can see when using debug.log for array.length it show 0.
The Code should capture Every GameObject on image below.
GameObject[] Antri;
private void Update()
{
CharacerSpawn();
EntranceWait -= Time.deltaTime;
if(EntranceInfo.EntranceStatus && EntranceWait < 0)
{
Antri = GameObject.FindGameObjectsWithTag("Karakter");
Debug.Log(Antri.Length);
KarakterInfo = GetClosest(Antri).GetComponent<Karakter_Movement>();
KarakterInfo.StopKarakter(EntranceObject.transform.position, 2f);
KarakterInfo.tag = "KarakterOnQueue";
EntranceWait = 3f;
}
}
GameObject GetClosest(GameObject[] Antri)
{
Debug.Log("Finding");
GameObject BestTarget = null;
Debug.Log("Proces01");
float closestDistanceSqr = Mathf.Infinity;
Debug.Log("Proces02");
foreach (GameObject PotentialTarget in Antri)
{
Debug.Log("Processing");
Vector3 directionToTarget = PotentialTarget.transform.position - EntranceObject.transform.position;
float dSqrToTarget = directionToTarget.sqrMagnitude;
if (dSqrToTarget < closestDistanceSqr)
{
closestDistanceSqr = dSqrToTarget;
BestTarget = PotentialTarget;
}
}
return BestTarget;
}
- Yes The PreFab Already Taged “Karakter”
- Foreach Action Won’t Work because array is empty.
Thank You in Advance