so basically i want to click a button then a new screen will pop up and i can make more buttons on that screen and i can make a back button i already know how to make the back button all i need to know is how to make a button that will change view into like a new canvas or whatever
Sounds to me like you want to get organized with canvasses! I personally like to use Panels for this on a single Canvas.
Then you can put a script (Monobehaviour) on the Canvas, which you can invoke from any Panel. Just use the inspector to make buttons fire a method in the Canvas above them via their onClick() method. And have these method show / hide the individual Panels. You can invoke more then one method per button if needed.
With only a few screens I don’t mind making them class variables, but you could make it as complex as you want. This example just alternates between two Panels when the pause button is pressed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseMenuScript : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject panelA;
public GameObject panelB;
private void Start()
{
panelA.SetActive(true);
panelB.SetActive(false);
Cursor.visible = false;
}
void Update()
{
if (Input.GetButtonDown("Cancel"))
{
if (GameIsPaused==true)
{
Resume();
} else
{
Pause();
}
}
}
public void Pause()
{
panelA.SetActive(true);
panelA.SetActive(false);
Time.timeScale = 0f;
Cursor.visible = true;
GameIsPaused = true;
}
public void Resume()
{
panelA.SetActive(false);
panelB.SetActive(true);
Time.timeScale = 1f;
GameIsPaused = false;
Cursor.visible = false;
}
public void Quit()
{
SaveDataSystem.Quit();
}
}
1 Like