Forum Discussion
bobbiannedoerr
10 years agoHonored Guest
2 cameras in a scene issue
I have two cameras in the same scene. One is a 1st person and the one is 3rd person. I am trying to make it be like Resident Evil, where if you went through a door, the player will view a room through a different camera. I have a script for this and there is box collider set to a trigger for that activates the cameras to switch. This works fine unit I add on the OVR scripts and then everything becomes a mess. The camera switch script does not work and you can only "see" through one camera throughout the scene. Help.
8 Replies
Replies have been turned off for this discussion
- cyberealityGrand ChampionThis is possible, and should not be a problem.
I believe you just have to deactivate the main camera, and then activate whatever other camera you want. At least that is how it works with Unity 5 native VR support. If you are using the Unity 4 integration it may be different. - bobbiannedoerrHonored GuestSo here is the code I have for the camera switch. Is there something wrong with that?
#pragma strict
var cam1 : Camera;
var cam2 : Camera;
private var walkedIn : boolean = false;
function Start()
{
cam1.GetComponent.<Camera>().enabled = true;
cam2.GetComponent.<Camera>().enabled = false;
}
function OnTriggerEnter(Col : Collider)
{
if(Col.tag == "Player")
{
walkedIn = !walkedIn;
}
}
function Update()
{
if(walkedIn == true)
{
cam1.GetComponent.<Camera>().enabled = false;
cam2.GetComponent.<Camera>().enabled = true;
}
if(walkedIn == false)
{
cam1.GetComponent.<Camera>().enabled = true;
cam2.GetComponent.<Camera>().enabled = false;
}
} - cyberealityGrand ChampionI believe the function call you want to use is this:
cam1.gameObject.SetActive(false);
cam2.gameObject.SetActive(true); - SvenVikingExpert ProtegeIf you have an OVRManager script, watch out that you're not disabling and enabling that as you switch cameras (since it's attached to the OVRCameraRig or player controller by default).
- bobbiannedoerrHonored GuestYeah, that is exactly the problem. VR only shows on one camera. So the code I have is not working at all. I keep messing with the code but nothing works. Any ideas would be greatly appreciated. Thanks!
- cyberealityGrand ChampionThat code you posted looks funky. Especially that you are switching the cameras in an update function and the cameras are hard-coded. For example. if you had that script on two triggers, it would never work (both would run constantly and whichever ran last would take control).
- bobbiannedoerrHonored GuestI watched some tutorials and came up with this. I am a beginning coder so I just don't know what else to try and have tried everything I can think of. Can you help me?
- SvenVikingExpert ProtegeFor only the specific problem I mentioned:
1. Move the OVRManager component to a new GameObject at the root of your hierarchy (i.e. don't make it a child of any other GameObject). You can probably just drag the component to the new GameObject, but if not, right-click and check for Copy Component/Paste as New Component.
2. Remove any OVRManager components from your OVRCameraRigs/PlayerControllers
If you're not using the Oculus Unity Integration or Oculus Tools prefabs, you won't have any OVRManager components and this doesn't apply to you.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 3 months ago
- 2 years ago
- 3 years ago
- 7 months ago