function CheckDistance () {
while (true) {
if ((cube1.position - cube2.position).magnitude < 10)
myLight.active = true;
else
myLight.active = false;
yield WaitForSeconds(5);
}
}
Active has been replaced by SetActive(bool). InsteAd of using magnitude use sqrMagnitude and 100 instead of 10. You could use a basic timer with float and delta time instead of wait foreclosed, but those won’t change much anyway. there is little to improve here.
function CheckDistance ()
{
var wait : YieldInstruction = new WaitForSeconds(5);
while (true)
{
myLight.SetActive((cube1.position - cube2.position).sqrMagnitude < distance * distance);
yield wait;
}
}