OneClickInteractable

This commit is contained in:
Michal Pikulski
2025-09-09 13:38:03 +02:00
parent aa127bf6d5
commit 07e88a88fe
4 changed files with 59 additions and 1 deletions

View File

@@ -68,4 +68,9 @@ public class Interactable : MonoBehaviour, ITouchInputConsumer
}
return anySuccess;
}
public void CompleteInteraction(bool success)
{
InteractionComplete?.Invoke(success);
}
}

View 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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 833a4ccef651449e973e623d9107bef5
timeCreated: 1757417586