Search Unity

Question How to assign a canvas image to a variable of type GameObject

Discussion in 'UGUI & TextMesh Pro' started by Uiquehonra, Feb 1, 2023.

  1. Uiquehonra

    Uiquehonra

    Joined:
    Sep 6, 2021
    Posts:
    1
    I'm trying to pass an image that will be my game over screen over the gameObject consists of an image with a button and a text inside

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using TMPro;
    7.  
    8.  
    9. public class GameController : MonoBehaviour
    10. {
    11.     public int total_score;
    12.     public TextMeshProUGUI scoreText;
    13.     public static GameController instance;
    14.     public GameObject game_over;
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         instance = this;
    19.     }
    20.  
    21.     public void updateScoreText()
    22.     {
    23.         scoreText.text = total_score.ToString();
    24.     }
    25.  
    26.     public void showGameOver()
    27.     {
    28.         game_over.SetActive(true);
    29.     }
    30. }
    31.