18 lines
607 B
C#
18 lines
607 B
C#
using UnityEngine;
|
|
|
|
public class UnitActionSystem : MonoBehaviour {
|
|
[SerializeField] private Unit SelectedUnit;
|
|
[SerializeField] private LayerMask UnitsLayerMask;
|
|
|
|
private void Update() {
|
|
HandleUnitSelection();
|
|
if (Input.GetMouseButtonDown(0))
|
|
SelectedUnit.Move(MouseWorld.GetPosition());
|
|
}
|
|
|
|
private void HandleUnitSelection() {
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, UnitsLayerMask);
|
|
SelectedUnit = raycastHit.collider.GetComponent<Unit>();
|
|
}
|
|
} |