So I’ve probably spent the previous hour trying to work through this code, to the point where I’ve merely copied and pasted it and it still doesn’t work… what is wrong with this? I am trying to only enable gameobjects which are a certain radius away from me. This code somewhat works as I will spawn in an some objects will have loaded, and some have not; however the ground directly below the player is also being disabled.
Collider[] c = Physics.OverlapSphere(this.gameObject.transform.position, 10);
foreach(Collider co in c)
{
if(Vector3.Distance(this.gameObject.transform.position, co.gameObject.transform.position) > 2)
{
gameObject.SetActive(false);
}
if(Vector3.Distance(this.gameObject.transform.position, co.gameObject.transform.position) < 2)
{
gameObject.SetActive(true);
}
}