- Home /
How to add pause screen with buttons
I have recently finished the unity official youtube flappy bird tutorial. I want to give user the option that, after striking one of the columns he can watch a reward video and continue with his score. If he strikes a column again then again this screen will pop up. This screen will have two buttons - watch video or let it be game over. I dont know how to do this.
Following is my class:
public class GameControl : MonoBehaviour
{
public float scrollspeed = -1.5f;
public static GameControl instance;
public GameObject gameOverText;
public bool gameover = false;
public Text scoretext;
private int score = 0;
void Awake()
{
if(instance == null)
{
instance = this;
}
else if (instance!=null)
{
Destroy(gameObject);
}
}
void Update()
{
if (gameover == true && Input.GetMouseButtonDown (0))
{
SceneManager.LoadScene(SceneManager.GetActiveScene ().buildIndex);
}
}
public void BirdScored()
{
if(gameover)
{
return;
}
score++;
scoretext.text = "Score: " + score.ToString();
}
public void BirdDied()
{
gameOverText.SetActive(true);
gameover = true;
}
}
This class takes care of the bird dying process. how can i add the option to watch add and continue the game here? Unity newbie here....
Comment
Have you solved this issue ? If yes, please help me for this.
Answer by haizathaneefa · Jul 14, 2020 at 09:40 AM
The code isnt tested but it should point you to the right direction.
public GameObject newLifeUI; // this will be your plus life UI
public GameObject gameOverUI; // game over UI is here
bool conditionChange; // checking to see if he can have a chance to continue
void Start()
{
newLifeUI.SetActive(false);
gameOverUI.SetActive(false);
}
void Update()
{
if (!conditionChange && /*have another condition here to detect if the player dies or not*/) // if the user dies the first time, let him have the chance to live again
{
newLifeUI.SetActive(true);
conditionChange = true;
}
if (conditionChange && /*have another condition here to detect if the player dies or not*/) // tough luck
{
gameOverUI.SetActive(true);
}
}
public void WatchVideo()
{
// your ad code will be here
}
public void QuitGame()
{
// quit game code will be here
}