I am trying to disable two scripts I have on two different game objects after a collision enters a trigger. I am not sure how to set it up becasue I keep getting errors for everything I try. Thanks for any advice and your time. Here is my script:
#pragma strict
var cameraFollow : CameraFollow;
var planeSelfMove : PlaneSelfMove;
function OnTriggerEnter( other : Collider )
{
if(other.gameObject.tag == "CameraTrigger")
{
cameraFollow = gameObject.GetComponent(CameraFollow).enabled = false;
planeSelfMove = gameObject.GetComponent(PlaneSelfMove).enabled = false;
}
}
Edit: I have changed my script to this (below) thanks to sharpshot124 because well it makes sense but now I get this null reference error:
NullReferenceException: Object reference not set to an instance of an object
StopCamera.OnTriggerEnter (UnityEngine.Collider collider) line 13
Line 13 is the cameraFollow.enabled = false;
So I am going into detail about my problem(which I should have done first). Here is what I am trying to do:
I am making a top-down shooter and the camera is in the orthographic view, I have “camera collision” around the edges so the player can’t go outside the camera’s view. I am using the top(top of the screen) camera collision to act as the collision for triggers to do things like spawn enemies and other things. And that works totally fine. But I get all the way through my level to the area where the boss fight is and I want to stop the camera from moving (it has a script attached to it that makes it move at a certain speed constantly). I changed my script to the necessities and to what sharpshot124 suggested. The game plays but when the top camera collision enters that trigger nothing happens and I get that error. The top camera collision does have a rigidbody so thats fine I believe. Also I’m attaching the script to the top camera collider. The trigger I am trying to get to work is named “SpawntriggerStopCamera”. Can anyone shed some light as to why I get that error? Again here is the revised script:
#pragma strict
var cameraFollow : CameraFollow;
function OnTriggerEnter( collider : Collider )
{
if(collider.gameObject.name == "SpawntriggerStopCamera")
{
cameraFollow = gameObject.GetComponent(CameraFollow);
cameraFollow.enabled = false;
}
}