Detecting a Null returned by a If statement.

Hello,

I'm trying to get something working, but on the condition that what is stated in the "If" is false.

    var BallActive : boolean = false;

function Update () {
}

function OnTriggerStay (other : Collider) {

        //Check if there's a ball is present in the level box.
    if (other.gameObject.GetComponent(Tagger).ball == true) {
        BallActive = true;
    }

    if (!(other.gameObject.GetComponent(Tagger).ball == true)) {
        BallActive = false;
    }

}

The code should put "BallActive" to true if he is detecting an object with the Tag "ball". But will out "BallActive" to untrue if it does not detect any object tagged with Ball. (All of that, inside the Trigger Box Collider)

Any ideas?

Edit:

It should return something as "Is there a ball present inside the Trigger?"

Cannot use OnTriggerExit, since the ball is destroyed inside the Trigger and is not detected as a ball "Exiting".

You should use OnTriggerEnter and OnTriggerExit to detect entering and exit because OnTriggerStay is only called when a collider is inside the trigger (if one of the two has a Rigidbody or CharacterController) and will not set the variable when the object leaves. To deal with potential enable/instantiation within the trigger, you could use OnTriggerStay in stead of OnTriggerEnter, but beware the overhead this will add. To deal with potential disable/destruction inside the trigger, you would use OnDisable and notify the trigger.

For a single ball.

Ball.js (Attached to your ball)

var activeTrigger : GameObject;

function OnDisable() {
    if(activeTrigger) {
        activeTrigger.SendMessage("BallDestroyed");
        activeTrigger = null;
    }
}

Trigger.js (Attached to your trigger)

var ballActive : boolean = false;

function OnTriggerStay(other : Collider) {
    if(other.gameObject.tag == "Ball") {
        ballActive = true;
        other.gameObject.GetComponent(Ball).activeTrigger = gameObject;
    }
}

function OnTriggerExit(other : Collider) {
    if(other.gameObject.tag == "Ball") {
        ballActive = false;
        other.gameObject.GetComponent(Ball).activeTrigger = null;
    }
}

function BallDestroyed() {
    ballActive = false;
}

or for multiple balls

Ball.js (Attached to your ball)

var activeTrigger : GameObject;

function OnDisable() {
    if(activeTrigger) {
        activeTrigger.SendMessage("BallDestroyed", gameObject);
        activeTrigger = null;
    }
}

Trigger.js (Attached to your trigger)

var balls : Array = new Array();

function OnTriggerStay(other : Collider) {
    if(other.gameObject.tag == "Ball") {
        for(var ball : GameObject in balls)
            if(ball == other.gameObject) return;
        other.gameObject.GetComponent(Ball).activeTrigger = gameObject;
        balls.Add(other.gameObject);
    }
}

function OnTriggerExit(other : Collider) {
    if(other.gameObject.tag == "Ball") {
        var i = int = 0;
        for(; i < balls.Length; i++)
            if(balls *== other.gameObject) break;*
 *balls.RemoveAt(i);*
 *other.gameObject.GetComponent(Ball).activeTrigger = null;*
 *}*
*}*
*function BallDestroyed(destroyed : GameObject) {*
 *var i = int = 0;*
 *for(; i < balls.Length; i++)*
 _if(balls *== destroyed) break;*_
 _*balls.RemoveAt(i);*_
_*}*_
_*```*_
if (other.gameObject.GetComponent(Tagger) != null)

if (other.gameObject.GetComponent(Tagger) == null)

Also, if you use camelCase for naming your variables, you are just being nicer to the world :) That means I suggest you name it ballActive