Check if a gameobject as active

Can someone please tell me what is wrong with this script. I want to check if the ‘protection’ particle effect is not playing before activating the ‘arrow hit’ effect. Thanks

#pragma strict

var arrowHit : GameObject;
var protection: GameObject;

function Start () {
    arrowHit.SetActive(false);
}

function OnTriggerEnter (other : Collider)
{
    if(other.gameObject.name == "arrow" && protection.!activeSelf)
        {
        arrowHit.SetActive(true);
        }
    else {
        arrowHit.SetActive(false);
        }
}

The place you inserted the exclamation mark to invert the boolean value is invalid. The dot operator used to access a member needs to be uninterrupted. Once you have the result of (protection.activeSelf), you can invert the entire expression by placing an exclamation mark before the whole thing:

    if (other.gameObject.name == "arrow" && !(protection.activeSelf))

The extra parentheses around protection.activeSelf are technically unnecessary, because the dot operator is guaranteed to be evaluated first, but they emphasize that the value inverted is the value that is returned by accessing the activeSelf member of protection.

1 Like

thanks heaps!