// Animancer // https://kybernetik.com.au/animancer // Copyright 2021 Kybernetik // using UnityEngine; namespace Animancer.Examples.FineControl { /// An object that can be interacted with. /// Doors /// https://kybernetik.com.au/animancer/api/Animancer.Examples.FineControl/IInteractable /// public interface IInteractable { /************************************************************************************************************************/ void Interact(); /************************************************************************************************************************/ } /// /// Attempts to interact with whatever the cursor is pointing at when the user clicks /// the mouse. /// /// Doors /// https://kybernetik.com.au/animancer/api/Animancer.Examples.FineControl/ClickToInteract /// [AddComponentMenu(Strings.ExamplesMenuPrefix + "Fine Control - Click To Interact")] [HelpURL(Strings.DocsURLs.ExampleAPIDocumentation + nameof(FineControl) + "/" + nameof(ClickToInteract))] public sealed class ClickToInteract : MonoBehaviour { /************************************************************************************************************************/ private void Update() { if (!Input.GetMouseButtonDown(0)) return; var ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out var raycastHit)) { var interactable = raycastHit.collider.GetComponentInParent(); if (interactable != null) interactable.Interact(); } } /************************************************************************************************************************/ } }