Destroy decal over time and if the camera is not looking at it. Not working.

I want to create a script that destroys the bullet decal after a certain amount of time but only if the player is not looking at it. The decal is a prefab spawned by another script. Here’s my script

#pragma strict
var respawnTimer = 0;
var delayTime = 10;

function Update() {
    respawnTimer += Time.deltaTime;
    if (respawnTimer > delayTime) {
        if (!renderer.isVisible) {
            Destroy(this.gameObject);
        }
    }
}

I don’t really know why it isn’t working but i hope you can help me. Thanks!

The issue is that respawnTimer and delayTime are integers, so the fractional amount Time.deltaTime is being rounded to 0 for the integer. You can fix it by setting the type.

var respawnTimer : float = 0;
var delayTime : float = 10;

or by just assigning floating point numbers:

var respawnTimer = 0.0;
var delayTime = 10.0