I dont understand what is wrong with my script

so what I want is if a player walks into a 2d box collider (with trigger on) the camera has to change
However when I attach this script to the object with the 2d box collider (which has trigger enabled)
Nothing happens! what is wrong?

#pragma strict

var FPScamera : Camera;
var TPcamera : Camera;

function OnTriggerEnter2D (other : Collider2D)

{
        FPScamera.GetComponent.<Camera>().enabled = false;
        TPcamera.GetComponent.<Camera>().enabled = true;
    }
   
    function OnTriggerExit2D (other : Collider2D)
    {
        FPScamera.GetComponent.<Camera>().enabled = true;
        TPcamera.GetComponent.<Camera>().enabled = false;
    }

The variables are already of type ‘Camera’.
There’s no need to use GetComponent again.

Do you use 2D components? 2D colliders and 2D rigidbody?

function OnTriggerExit2D (other : Collider2D)
    {
        FPScamera.enabled = true;
        TPcamera.enabled = false;
    }

I

My player and my object both use box Collider 2D with trigger on

At least one of them has to have a rigidbody

Check the bottom if this page for the complete chart of what causes what to call a collision.

1 Like