35 lines
858 B
C#
35 lines
858 B
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class UnitCommandGiver : MonoBehaviour
|
|
{
|
|
[SerializeField] private UnitSelectionHandler _unitSelectionHandler;
|
|
[SerializeField] private LayerMask _layerMask;
|
|
|
|
private Camera _camera;
|
|
|
|
private void Start()
|
|
{
|
|
_camera = Camera.main;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!Mouse.current.rightButton.wasPressedThisFrame) return;
|
|
|
|
Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
|
|
|
|
if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, _layerMask)) return;
|
|
|
|
TryMove(hit.point);
|
|
}
|
|
|
|
private void TryMove(Vector3 destination)
|
|
{
|
|
foreach (var selectedUnit in _unitSelectionHandler.SelectedUnits)
|
|
{
|
|
selectedUnit.UnitMovement.CmdMove(destination);
|
|
}
|
|
}
|
|
} |