Question by
bherdm · May 28, 2016 at 02:33 PM ·
cameramultiplayerviewport
How can I change the viewport rect of two active cameras at runtime? - Splitscreen Multiplayer
I'm able to change the main camera's viewport at runtime, and the script is finding Cam2, but I can't adjust its rect.
The commented out line is the offender.
This script is currently attached to the main camera.
Thanks!
public class P1Cam : MonoBehaviour {
GameObject Cam2;
void Start(){
Cam2 = GameObject.Find ("Cam2");
if (Cam2) {
Debug.Log ("found Cam2");
//Cam2.rect = new Rect (0.5f, 0, 0.5f, 0);
Camera.main.rect = new Rect (0, 0, 0.5f, 1);
} else {
Camera.main.rect = new Rect (0, 0, 1, 1);
}
}
}
Comment
Best Answer
Answer by bherdm · May 28, 2016 at 02:51 PM
Bah, 10 minutes later I got it.
public class P1Cam : MonoBehaviour {
private Camera Cam2;
void Start(){
Cam2 = GameObject.Find ("Cam2").GetComponent<Camera> ();
if (Cam2) {
Debug.Log ("found Cam2");
Cam2.rect = new Rect (0.5f, 0, 0.5f, 1);
Camera.main.rect = new Rect (0, 0, 0.5f, 1);
} else {
Camera.main.rect = new Rect (0, 0, 1, 1);
}
}
}
Your answer
Follow this Question
Related Questions
Converting World coordinates to Viewport in split screen 1 Answer
Missing shadows when using a custom oblique projection matrix 0 Answers
MLAPI - Lost with instantiate 1 Answer
PUN fps help 0 Answers