| | | 1 | | using UnityEngine; |
| | | 2 | | using UnityEngine.InputSystem; |
| | | 3 | | |
| | | 4 | | using TMPro; |
| | | 5 | | |
| | | 6 | | namespace DroneGame |
| | | 7 | | { |
| | | 8 | | class Selection : MonoBehaviour |
| | | 9 | | { |
| | | 10 | | public Transform selected; |
| | | 11 | | TextMeshProUGUI _informationText; |
| | | 12 | | |
| | | 13 | | void Awake() |
| | 0 | 14 | | { |
| | 0 | 15 | | _informationText = GameObject.Find("Canvas/SelectionInformation") |
| | | 16 | | .GetComponent<TextMeshProUGUI>() |
| | | 17 | | ?? throw new("Component Not found"); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary>Function executed when the players select a tile</summary> |
| | | 21 | | void OnMouseClick(InputValue value) |
| | 0 | 22 | | { |
| | 0 | 23 | | var mousePosition = Mouse.current |
| | | 24 | | .position |
| | | 25 | | .ReadValue(); |
| | 0 | 26 | | var ray = Camera.main |
| | | 27 | | .ScreenPointToRay(mousePosition); |
| | | 28 | | |
| | 0 | 29 | | if (Physics.Raycast(ray, out RaycastHit hit)) |
| | 0 | 30 | | { |
| | 0 | 31 | | selected = hit.collider |
| | | 32 | | .transform |
| | | 33 | | .parent; |
| | 0 | 34 | | var connector = selected.GetComponent<Connector>(); |
| | 0 | 35 | | _informationText.text = $@"From {connector.from.letterCoordinate} |
| | | 36 | | To {connector.to.letterCoordinate} |
| | | 37 | | Distance {connector.distance}"; |
| | 0 | 38 | | } |
| | 0 | 39 | | } |
| | | 40 | | } |
| | | 41 | | } |