- Home /
Triggers not changing cameras
The character has both Rigidbody and Box collider. I used cubes which I named for example Trigger01Forward and Trigger01Back which has box colliders but it was set as Trigger where the character can walk through it. The script as a generic to operate on all the cameras requires dragging the camera number to turn on and the Camera Number to turn off in the Inspector tab. However, when the character walks through the triggers the cameras do not change. The attached image gives a better understanding which also includes the C# coding. Could use some advice and assistance.
It would help if you provide more information on what steps you have taken to narrow down the issue so we know where to look for the problem.
Is the collision detected at all? Does it successfully match the tag? For example, if you add a Debug.Log inside the other.tag == "Player" does it print?
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
Debug.Log("Collision detected with player");
camerOn.SetActive(true);
cameraOff.SetActive(false);
Debug.Log("Camera states changed");
}
}
Answer by J_Ripley · Dec 28, 2021 at 04:38 PM
Thank you for the input. The console does print out collision detected and the Camera states changed. Basically having to modify the triggers. While researching I did run across a video on Cinemachines State Driven Camera system. Since this will be an action-packed system, while at the same, building up my grandchildren's critical thinking skills on mathematics and decision-making process, I may wind up doing two different versions of this, one with camera changing by triggers and the other trying out the Cinemachine State Driven Camera system in order to compare which provides the better angles for actions scenes and etc. Thank you for the input and the two lines of code.
Answer by endasil_unity · Dec 28, 2021 at 10:09 PM
Okay, if that did not help you solve the issue it narrows down the troubleshooting field a bit more. Your image is very blurry so I can't see much detail there. Is it the camera component or game object that is deactivated? I noticed that you're activating and deactivating game objects, so if it is the camera component on the game object that you have deactivated, this would not turn it on. If you look in the inspector after entering the trigger, are those game objects disabled/enabled? Is the camera you're disabling from your script the active camera that is displaying the screen? That is if you disable this camera manually, does the game view go blank with the no camera rendering text?
Thank you for contacting me back. Camera01 is on while the others are off at the start of the game. It is viewing the character's left profile or side. Camera03 is located at the far wall in front of the character but is turned off and the angle of Camera03 is viewing the front of the character if it was turned on. Camera26 is above the character and slightly past the character's right shoulder. There are two Triggers, side by side should the character turn left and walks across the hallway. The first trigger the character walks through turns Camera01 off and turns Camera26 on. The second trigger he crosses immediately behind the first does the reverse should the character see danger, turns around and walks in the opposite direction. Camera01 does go off for a few seconds but immediately turns back on and Camera26 turns off where you are unable to see the character.