Skip to content

Instantly share code, notes, and snippets.

@smkplus
Created April 9, 2020 16:04
Show Gist options
  • Select an option

  • Save smkplus/ee419d48cf5e6848a41c732a3fd63829 to your computer and use it in GitHub Desktop.

Select an option

Save smkplus/ee419d48cf5e6848a41c732a3fd63829 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class UIComponent : MonoBehaviour
{
[SerializeField] private Text scoreText;
[SerializeField] private Text lifeText;
[SerializeField] private Image gameOverOverlay;
private void Start()
{
InitializeUI();
}
private void InitializeUI()
{
gameOverOverlay.gameObject.SetActive(false);
if (scoreText != null)
{
scoreText.text = GameConstants.SCORE_TXT + "0";
scoreText.gameObject.SetActive(true);
}
if (lifeText != null)
{
lifeText.text = GameConstants.LIFE_TXT + GameConstants.INITIAL_LIFE.ToString();
lifeText.gameObject.SetActive(true);
}
}
public void DisableTextUI()
{
if (scoreText != null)
{
scoreText.gameObject.SetActive(false);
}
if (lifeText != null)
{
lifeText.gameObject.SetActive(false);
}
}
public void UpdateScore(int score)
{
if (scoreText != null)
{
scoreText.text = GameConstants.SCORE_TXT + score.ToString();
}
}
public void UpdateLife(int life)
{
if (lifeText != null)
{
lifeText.text = GameConstants.LIFE_TXT + life.ToString();
}
}
public void ShowGameOverOverlay()
{
gameOverOverlay.gameObject.SetActive(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment