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 タレット設置機能 7/14 47 UpgradeのUIを実装 タレット設置済みで実施するとUpgradeUIを開くようにする

Last updated at Posted at 2023-05-04

概要

目次

今回はタレット設置済みのNodeオブジェクトをクリックしたとき、タレットアプデUIを表示するようにします。

以下gifアニメはタレット設置済みのNodeオブジェクトをクリックしたときUIが表示される様子です。

7-14.gif

開発環境

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

UnityEditor上の設定

UIを新規作成します。
UIは真ん中の下部に配置するにはAltキーを押してアンカープリセットを選択します。
iiiii.gif

UIManagerコンポーネントにNodeUIPanelをアタッチします。
image.png

実装のポイント

UIManagerクラスの内容を修正します。
新規メソッドShowNodeUIを加えます。
ShowNodeUIメソッドをはNodeUIを表示するメソッドです。

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;
    
    private Node _currentNodeSelected;

    public void CloseTurretShopPanel()
    {
        turretShopPanel.SetActive(false);
    }
    
+    private void ShowNodeUI()
+    {
+        nodeUIPanel.SetActive(true);
+    }
    private void NodeSelected(Node nodeSelected)
    {
        _currentNodeSelected = nodeSelected;
        if (_currentNodeSelected.IsEmpty())
        {
            turretShopPanel.SetActive(true);
        }
+        else
+        {
+            ShowNodeUI();
+        }
    }
    private void OnEnable()
    {
        Node.OnNodeSelected += NodeSelected;
    }

    private void OnDisable()
    {
        Node.OnNodeSelected -= NodeSelected;
    }
}


参考

Section8 47

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?