0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

タワーデフェンスゲーム Unity タレット設置機能 12/14  49 ライフと金額のUIを実装

Posted at

概要

目次

今回は画面左上にあるライフと金額UIを実装します。
下gifアニメはタレットの強化で金額が減って、敵を撃退できなくライフが減っている様子です。

12-14.gif

開発環境

IDE:Rider
Unity:2020.3.42(LTS)
OS:Windows10

UnityEditor上の設定

Canvas以下にCoinPanelを作成

image.png

UIManagerスクリプトにLifes-TMPとCoins-TMPをアタッチします。

image.png

実装のポイント

下図はCurrencySytemから金額情報を取得するときの流れです。

image.png

下図はLevelManagerからライフ情報を取得するときの流れです。

image.png

コード部分

UIManager

UIManager.cs
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class UIManager : Singleton<UIManager>
{
    [Header("Panels")]
    [SerializeField] private GameObject turretShopPanel;

    [SerializeField] private GameObject nodeUIPanel;
    [SerializeField] private TextMeshProUGUI upgradeText;
    [SerializeField] private TextMeshProUGUI sellText;
    [SerializeField] private TextMeshProUGUI turretLevelText;
+    [SerializeField] private TextMeshProUGUI totalCoinsText;
+    [SerializeField] private TextMeshProUGUI lifesText;
    public TurretUpgrade TurretUpgrade { get; set; }
    private Node _currentNodeSelected;

    private void Update()
    {
+        totalCoinsText.text = CurrencySystem.Instance.TotalCoins.ToString();
+        lifesText.text = LevelManager.Instance.TotalLives.ToString();
        
    }
    // 中略
}


参考

Section8 49

github コミット分

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?