Aetheria/Assets/Scripts/UI/ClickRaycaster.cs
hyperion51 698263ce63 Entity Properties & Thermal Regulation
Entities such as colonies and ships can now be clicked on to reveal their properties or context menus
Orbital Colony loadout now has a new item (thermostatic heater) which itself has a new behavior type (Thermotoggle) allowing it to regulate its temperature for more agreeable living conditions
Fixed stat modifiers for hull stats (e.g. Hull Expansion)
Widened property label in DB inspector
2020-05-26 01:12:06 +01:00

29 lines
844 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickRaycaster : MonoBehaviour
{
public event Action<PointerEventData> 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(pointer);
};
}
}