OneClickInteractable
This commit is contained in:
35
Assets/Scripts/Interactions/OneClickInteraction.cs
Normal file
35
Assets/Scripts/Interactions/OneClickInteraction.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// MonoBehaviour that immediately completes an interaction when started.
|
||||
/// </summary>
|
||||
public class OneClickInteraction : MonoBehaviour
|
||||
{
|
||||
private Interactable interactable;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
interactable = GetComponent<Interactable>();
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.StartedInteraction += OnStartedInteraction;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.StartedInteraction -= OnStartedInteraction;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStartedInteraction()
|
||||
{
|
||||
if (interactable != null)
|
||||
{
|
||||
interactable.CompleteInteraction(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user