Aetheria/Assets/Scripts/UI/ClickRaycaster.cs
hyperion51 af88788e4f Local AI Testing & Interactive Tech Tab
Refactored game loop to allow full local testing
Added AI controller abstractions
Added ability to save database to local copy for offline testing
Tech Tab is now interactive, has properties panel
2020-04-23 03:31:17 +01:00

28 lines
791 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickRaycaster : MonoBehaviour
{
public event Action OnClickMiss;
public Camera RayCamera;
private ClickCatcher _clickCatcher;
void Start()
{
_clickCatcher = GetComponent<ClickCatcher>();
_clickCatcher.OnClick += pointer =>
{
RaycastHit hit;
Physics.Raycast(RayCamera.ScreenPointToRay(pointer.position), out hit);
if (hit.collider != null)
{
var clickable = hit.collider.GetComponent<ClickableCollider>();
if (clickable != null)
clickable.Click(pointer);
else OnClickMiss?.Invoke();
}
};
}
}