다양한 기록

[Fortress Craft] Castle 생성 UI, 가격 설정 본문

유니티 엔진/Fortress Craft

[Fortress Craft] Castle 생성 UI, 가격 설정

라구넹 2025. 2. 5. 21:39

파란 버튼 누르면 돈이 충분히 있을 경우 캐슬 스폰 가능

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Agit.FortressCraft
{
    public class SpawnCastleCostManager : MonoBehaviour
    {
        public static SpawnCastleCostManager Instance { get; set; }

        [SerializeField] private Text costText;
        public List<int> costByLevel = new List<int>();
        public int level { get; private set; }

        private void Awake()
        {
            Instance = this;
            level = 0;
            costText.text = costByLevel[0].ToString();
        }

        public int GetCost(int level)
        {
            return costByLevel[level];
        }

        public void LevelUp()
        {
            if (level > 15) return;
            ++level;
            costText.text = costByLevel[level].ToString();
        }
    }
}

스폰캐슬매니저에서 가격 관리

 

Player에서 리워드매니저에 접근해서 돈이 있는지 체크하고 캐슬 생성