Main Menu Rules
Started, should be finished in fact 👍
This commit is contained in:
parent
9a67bd00aa
commit
97aa74cacb
26 changed files with 2020 additions and 1 deletions
71
Assets/Scripts/UI/UnitButton.cs
Normal file
71
Assets/Scripts/UI/UnitButton.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using System;
|
||||
|
||||
public class UnitButton : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
[SerializeField] GameObject unitPrefab;
|
||||
[SerializeField] ShopCanvas unitPlacement;
|
||||
public event Action OnClicked, OnExit;
|
||||
|
||||
|
||||
private int cost;
|
||||
[SerializeField] TextMeshProUGUI texteCout;
|
||||
[SerializeField] TextMeshProUGUI unit;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private void Start()
|
||||
{
|
||||
cost = GlobalsVariable.prices[unit.text];
|
||||
texteCout.text = cost.ToString();
|
||||
}
|
||||
|
||||
public void StartPlacing()
|
||||
{
|
||||
if (GlobalsVariable.money < cost)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("I'm *in");
|
||||
|
||||
|
||||
OnClicked += PlaceUnit;
|
||||
OnExit += StopPlacing;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PlaceUnit()
|
||||
{
|
||||
Vector3 mousePos = unitPlacement.MapPosition();
|
||||
GameObject go = Instantiate(unitPrefab, mousePos, Quaternion.identity);
|
||||
GlobalsVariable.Pay(cost);
|
||||
OnClicked -= PlaceUnit;
|
||||
|
||||
}
|
||||
|
||||
public void StopPlacing()
|
||||
{
|
||||
OnClicked -= PlaceUnit;
|
||||
OnExit -= StopPlacing;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
OnExit?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue