Hi, I have UI that I activate using JoystickButton7 through the following script:
using UnityEngine;
using System.Collections;
public class MenuToggle : MonoBehaviour
{
private Canvas CanvasObject; // Assign in inspector
void Start()
{
CanvasObject = GetComponent<Canvas>();
}
void Update()
{
if (Input.GetKeyUp(KeyCode.JoystickButton7))
{
CanvasObject.enabled = !CanvasObject.enabled;
}
}
}
The problem is that the UI has a main camera and so I need to deactivate the Main Scene camera so the new UI camera can be viewed.
Then when I press the JoystickButton7 again the main camera should reactivate. As the UI and its camera are deactivated.
So I have been throwing stuff at a wall and hoping something sticks because I don’t know C# well enough to even try and solve this myself. And so I appreciate any help offered.
Many thanks
Oh, I have been messing around with something like this but I cant get it to function.
I suspect the main problem you’re having is that most of the “Find” methods can’t find GameObjects that are inactive, so you wouldn’t be able to turn it back on. You should try storing a reference to the camera when you find it. For example:
I also noticed while typing that that you were trying “.active”, which doesn’t exist. You use .SetActive to change its active state, and either .activeSelf or .activeInHierarchy to read its state.
As in the image below, I added the camera toggle script to the OptionsMenuActivator game object along with the above mentioned MenuManager/toggle script as above.
As a new developer I am wondering how to change the camera using the 1 and 2 buttons on the keypad / number row
is it just to delete joystick button 7 and add key 1 / 2?