Home>

We are currently creating a 2D shooting game (for smartphones).
Currently, I am doing well up to displaying the game over text when the player hits the enemy, but I want to display the RETRY button at the same time as displaying the game over text, but it does not display well.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class GameController: MonoBehaviour
{
public GameObject TitleText;
public GameObject gameOverText;
public Text scoreText;
int score = 0;
// Stage number text
public Text stageNumberText;

public GameObject stageNextButton;
public GameObject retryButton;
public void Start() // Game over text is gone, score text is displayed, hide button (stagenextbutton is erased, retry is erased)
{
gameOverText.SetActive(false);
scoreText.text = "SCORE:" + score;
HideButtons();
}

public void AddScore() //Increase Score by 100
{
score += 100;
scoreText.text = "SCORE:" + score;
}

public void GameOver() //Display GameOver characters and issue retry button
{
gameOverText.SetActive(true);
Debug.Log("aa");
ShowRetryButtons();
Debug.Log("bb");
}

public void nextScene() //Load Main Scene
{
SceneManager.LoadScene("Main");

}

public void HideButtons()
{
stageNextButton.SetActive(false);
retryButton.SetActive(false);
}
public void ShowRetryButtons()
{
gameOverText.SetActive(true);

Debug.Log("cc");

}

}
If i try Debug.Log as above, you can get to the console as shown in the image below. I'm not sure why retryButton is not. I would appreciate your advice. ..

  • Answer # 1

    ShowRetryButtonsFor processingretryButton.SetActive(true);Is not written.

  • Answer # 2

    The script seems to have had no problems.
    In the inspector, I added a script to the button I want to show or hide, but when I remove it, the retry button and game over button are displayed when the game is over!