Start Unit PLacement
navmesh not working yet
This commit is contained in:
parent
afe60bae57
commit
49c5e6df9f
19 changed files with 40382 additions and 89 deletions
|
@ -26,7 +26,7 @@ public class CameraMouvement : MonoBehaviour
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
print("Update");
|
||||
//print("Update");
|
||||
var mouvement = moveSpeed * Time.deltaTime * (new Vector3(_moveInput.y, 0, -_moveInput.x));
|
||||
transform.Translate(mouvement, Space.World);
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using System;
|
||||
|
||||
public class Cost : MonoBehaviour
|
||||
{
|
||||
private int cost;
|
||||
[SerializeField] TextMeshProUGUI texteCout;
|
||||
[SerializeField] TextMeshProUGUI unit;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
cost = GlobalsVariable.prices[unit.text];
|
||||
texteCout.text = cost.ToString();
|
||||
}
|
||||
}
|
70
Assets/Scripts/UnitButton.cs
Normal file
70
Assets/Scripts/UnitButton.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using System;
|
||||
|
||||
public class UnitButton : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private GameObject Mask;
|
||||
|
||||
[SerializeField] GameObject unitPrefab;
|
||||
[SerializeField] UnitPlacement 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");
|
||||
GlobalsVariable.Pay(cost);
|
||||
//Mask.SetActive(true);
|
||||
OnClicked += PlaceUnit;
|
||||
OnExit += StopPlacing;
|
||||
}
|
||||
}
|
||||
|
||||
void PlaceUnit()
|
||||
{
|
||||
Vector3 mousePos = unitPlacement.MapPosition();
|
||||
GameObject go = Instantiate(unitPrefab);
|
||||
go.transform.position = mousePos;
|
||||
|
||||
}
|
||||
|
||||
public void StopPlacing()
|
||||
{
|
||||
//Mask.SetActive(false);
|
||||
OnClicked -= PlaceUnit;
|
||||
OnExit -= StopPlacing;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
OnExit?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
21
Assets/Scripts/UnitPlacement.cs
Normal file
21
Assets/Scripts/UnitPlacement.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class UnitPlacement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera _camera;
|
||||
private Vector3 lastPosition;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
public Vector3 MapPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray,out hit, 100, placementLayer))
|
||||
{
|
||||
lastPosition = hit.point;
|
||||
}
|
||||
return lastPosition;
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitPlacement.cs.meta
Normal file
2
Assets/Scripts/UnitPlacement.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f4860e618b2df541be28bc841173bb6
|
|
@ -4,6 +4,9 @@ using UnityEngine;
|
|||
|
||||
public static class GlobalsVariable
|
||||
{
|
||||
|
||||
public static int money=100;
|
||||
|
||||
public static List<AbstractUnit> AliveUnitsTeamA = new List<AbstractUnit>();
|
||||
public static List<AbstractUnit> AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
|
||||
|
@ -18,4 +21,14 @@ public static class GlobalsVariable
|
|||
{ "Sorcičre",3 },
|
||||
{ "Golem",8 }
|
||||
};
|
||||
|
||||
public static void Pay(int X)
|
||||
{
|
||||
money -= X;
|
||||
}
|
||||
|
||||
public static void Gain(int Y)
|
||||
{
|
||||
money += Y;
|
||||
}
|
||||
}
|
||||
|
|
22
Assets/Scripts/Wallet.cs
Normal file
22
Assets/Scripts/Wallet.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Wallet : MonoBehaviour
|
||||
{
|
||||
|
||||
private int argent;
|
||||
[SerializeField] TextMeshProUGUI argentTexte;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
argent = GlobalsVariable.money;
|
||||
argentTexte.text = argent.ToString();
|
||||
}
|
||||
}
|
2
Assets/Scripts/Wallet.cs.meta
Normal file
2
Assets/Scripts/Wallet.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d14bc8b31a8eb5a4ebec1a208eda3a26
|
Loading…
Add table
Add a link
Reference in a new issue