Placement of units and crown
youhou
This commit is contained in:
parent
769264c79b
commit
abeb6fbf83
6 changed files with 288 additions and 17 deletions
64
Assets/Scripts/Crown.cs
Normal file
64
Assets/Scripts/Crown.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Crown : MonoBehaviour
|
||||
{
|
||||
|
||||
public event Action OnClicked;
|
||||
private bool crowned=false;
|
||||
[SerializeField] TextMeshProUGUI texte;
|
||||
|
||||
|
||||
[SerializeField] private Camera _camera;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
texte.enabled = false;
|
||||
}
|
||||
|
||||
public void StartCrown()
|
||||
{
|
||||
if (!crowned)
|
||||
{
|
||||
Debug.Log("Crowning right now");
|
||||
texte.enabled = true;
|
||||
OnClicked += Crowning;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GameObject ObjectPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, placementLayer))
|
||||
{
|
||||
OnClicked -= Crowning;
|
||||
return hit.transform.gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Crowning()
|
||||
{
|
||||
GameObject unit = ObjectPosition();
|
||||
unit.GetComponent<AbstractUnit>().IsQueen = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/Crown.cs.meta
Normal file
2
Assets/Scripts/Crown.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d450b2674075c944a534648ddbb139c
|
|
@ -12,6 +12,7 @@ public class UnitButton : MonoBehaviour
|
|||
[SerializeField] GameObject unitPrefab;
|
||||
[SerializeField] UnitPlacement unitPlacement;
|
||||
public event Action OnClicked, OnExit;
|
||||
private bool clicked;
|
||||
|
||||
private int cost;
|
||||
[SerializeField] TextMeshProUGUI texteCout;
|
||||
|
@ -33,10 +34,12 @@ public class UnitButton : MonoBehaviour
|
|||
else
|
||||
{
|
||||
Debug.Log("I'm *in");
|
||||
GlobalsVariable.Pay(cost);
|
||||
|
||||
//Mask.SetActive(true);
|
||||
|
||||
OnClicked += PlaceUnit;
|
||||
OnExit += StopPlacing;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +47,8 @@ public class UnitButton : MonoBehaviour
|
|||
{
|
||||
Vector3 mousePos = unitPlacement.MapPosition();
|
||||
GameObject go = Instantiate(unitPrefab, mousePos, Quaternion.identity);
|
||||
GlobalsVariable.Pay(cost);
|
||||
OnClicked -= PlaceUnit;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ using UnityEngine.AI;
|
|||
public class UnitPlacement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera _camera;
|
||||
private Vector3 lastPosition;
|
||||
public Vector3 lastPosition;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
public Vector3 MapPosition()
|
||||
|
|
|
@ -12,7 +12,7 @@ public abstract class AbstractUnit : MonoBehaviour
|
|||
{
|
||||
public float price;
|
||||
[field: SerializeField] public bool IsTeamA { get; private set; }
|
||||
[field: SerializeField] public bool IsQueen { get; private set; }
|
||||
[field: SerializeField] public bool IsQueen { get; set; }
|
||||
|
||||
public abstract void TakeDamage(float damage);
|
||||
public abstract void Heal(float heal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue