- Home /
Why do all gameobjects not dissapear from view when I switch cameras?
I am having trouble with camera switching. I have two cameras: "Camera1" and "Camera2". A "button script" attached to Camera1 allows a switch to Camera2. It also positions the cameras. There is a gameobject called "Main Menu" that is meant to be a background image for the button ; it is a GUI texture background (a flat jpeg image) .
At game start, the button works (sort of!) ; clicking it causes "Camera" components to be enabled and disabled appropriately, and it changes the game view background.
Problem: the GUI texture does not disappear from game view, and nor does the button!
When I click the button, I want a complete change of game view, i.e., I want both the button and its GUI texture background to disappear from game view. But I am not getting that. I would appreciate any help to understand why.
How can I make a GUI texture visible ONLY because it is in front of Camera1? How do I make the button visible ONLY when Camera1 is active?
Here is my button script:
using UnityEngine;
using System.Collections;
public class PageButton : MonoBehaviour
{
public GameObject MainMenu ;
public Camera cam1, cam2 ;
void Start() {
// position the Main Menu
MainMenu = GameObject.Find("MainMenu");
MainMenu.transform.position = new Vector3 (0, 0, 0);
// Setup Camera1
cam1 = GameObject.Find("Camera1" ).GetComponent<Camera>() as Camera;
cam1.transform.position = new Vector3 (0, 0, -10);
cam1.orthographic = true;
cam1.orthographicSize = 5f;
cam1.enabled = true;
// Setup Camera2
cam2 = GameObject.Find("Camera2" ).GetComponent<Camera>() as Camera;
cam2.transform.position = new Vector3 (100, 100, 10);
cam2.enabled = false;
cam2.transform.Rotate(0,270,0, Space.World);
cam2.orthographic = true;
cam2.orthographicSize = 5f;
}
public void OnGUI()
{
if(GUI.Button(new Rect(580,340,20,20), ">")) {
Debug.Log ("Button pressed");
cam1.enabled = false;
cam2.enabled = true;
}
} // end OnGUI()
} // end PageButton
Your answer
![](https://koobas.hobune.stream/wayback/20220612001954im_/https://answers.unity.com/themes/thub/images/avi.jpg)