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
-
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!
Related articles
- [unity2d] app crashes during scene transition
- i can't successfully attach a method to a button ui in unity
- unity - bind left mouse button or tap in input system
- a question about unity please tell me how to display animatorsettrigger in onclick() of button
- unity - i don't know how to attach a method and target button object to onclick from script
- i want to display both reorderablelist and other properties in the inspector [unity]
- i want to display it when i press the submit button on the php form
- i can't use anykeydown and button click process together in unity
- javascript - please tell me how to display the button
- c# - unity) i want to display prefabs in 3 columns
- unity - i want to optimize the display of large numbers of dynamic objects
- i want to display the unity deletion confirmation screen, but the screen is displayed, but i do not wait for the input of ok and
- i want to jump once for each jump button in a unity 2d action game
- i want the button to proceed to the next in unity to appear when the game clear is displayed in the ui
- java - i want to display the toast by clicking the button
- unity: is it possible to display multiple windows?
- unity - text of ui changed by processing of button placed by editor extension is not updated
- i want to display admob test ad in unity
- c# - navigation setting of button does not work well in unity ui
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs
ShowRetryButtons
For processingretryButton.SetActive(true);
Is not written.