Help With Colliders

Hello,

I have a prefab of a turret (which has its own collider - trigger), I also have a game boundary which is just a trigger collider (tagged GameBoundary).

I basically want a boolean to be true if turret touches game boundary.

EG:

if(turretCollider collides with collider tagged GameBoundary){
   madeUpBoolean = true;
}

So if the turret makes contact with the game boundary: madeUpBoolean = true

How would one do that?

Thanks

You'd use the OnCollisionEnter, and then take what is colliding with it, and check the tag of that object, and if it's equal, than do it:

function OnCollisionEnter(collision : Collision) {
    if(collision.gameObject.tag == "GameBoundary")
    {
        madeUpBoolean = true;
    }
}

Put this on your turret:

JS:

function OnCollisionEnter(col : Collision) {
    if(col.collider.GameObject.CompareTag("GameBoundary")) {
        madeUpBoolean = true;
    }
}

C#:

void OnCollisionEnter(Collision col) {
    if(col.collider.GameObject.CompareTag("GameBoundary")) {
        madeUpBoolean = true;
    }
}

Please note that the above code is untested and may contain errors.

Someone can delete this.........