Hello everyone.
Could someone suggest me a good java script that could help my objects(Enemies) disappear while camera (player) is move and object is out of view (few meters or out of the zone)
Thank you for your time
-Metalbreathe
Hello everyone.
Could someone suggest me a good java script that could help my objects(Enemies) disappear while camera (player) is move and object is out of view (few meters or out of the zone)
Thank you for your time
-Metalbreathe
This should do the trick, you can set how far away the player has to be for it to disappear:
var isVisible = false;
var ActiveRange = 50;
function OnBecameVisible () {
isVisible = true;
}
function OnBecameInvisible () {
isVisible = false;
}
function Update ()
{
if(!isVisible && Vector3.Distance(Camera.main.transform.position, transform.position) > ActiveRange)
{
enabled = false;
}
}