Question by
OrionGamesInc · Feb 08, 2016 at 01:55 PM ·
cameracamera-lookcameras
Run script only when camera is looking away
Hi. I don't know if this is possible, but i'd really like to give it a try. So I've already added a working destroy script (below) on some objects in my game, I just would like an addition to the script so that it would only run if the camera was not facing the objects. Each object has it's own destroy script, with a timer. Thanks to anyone with any helpful material or scripts.
#pragma strict
var Seconds = 10; //this is different for each object
function Update(){
Destroy();
}
function Destroy(){
yield WaitForSeconds(Seconds);
Destroy(gameObject);
}
Comment
Answer by Jordi-Bonastre · Feb 08, 2016 at 03:34 PM
If you only have a camera in your scene, you could use the renderer of those GO. isVisible and OnBecameInvisible should help you.
http://docs.unity3d.com/ScriptReference/Renderer-isVisible.html
http://docs.unity3d.com/ScriptReference/Renderer.OnBecameInvisible.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612063255im_/https://answers.unity.com/themes/thub/images/avi.jpg)