2024-09-24 10:35:49 +00:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
2025-02-10 02:13:46 +00:00
|
|
|
namespace DDD.Tycoons
|
2024-09-24 10:35:49 +00:00
|
|
|
{
|
|
|
|
public abstract class LiquidIngredient : MonoBehaviour
|
|
|
|
{
|
|
|
|
[FormerlySerializedAs("_spriteRenderer")]
|
|
|
|
[SerializeField]
|
|
|
|
protected SpriteRenderer SpriteRenderer;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_rigidbody2D")]
|
|
|
|
[SerializeField]
|
|
|
|
protected Rigidbody2D Rigidbody2D;
|
|
|
|
|
|
|
|
[SerializeField, Range(0f, 2f)]
|
|
|
|
protected float _distanceThreshold = 0.5f;
|
|
|
|
|
|
|
|
protected bool CanInteraction;
|
|
|
|
protected Collider2D TargetCollider;
|
|
|
|
|
|
|
|
public static event Action OnReachedTarget;
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!TargetCollider || !CanInteraction) return;
|
|
|
|
|
|
|
|
var closestPoint = TargetCollider.ClosestPoint(transform.position);
|
|
|
|
var distance = Vector2.Distance(transform.position, closestPoint);
|
|
|
|
|
|
|
|
if (distance < _distanceThreshold)
|
|
|
|
{
|
|
|
|
ReachedObject();
|
|
|
|
}
|
|
|
|
}
|
2024-11-11 02:02:24 +00:00
|
|
|
|
|
|
|
public virtual void ReachedObject()
|
|
|
|
{
|
|
|
|
OnReachedTarget?.Invoke();
|
|
|
|
}
|
2024-09-24 10:35:49 +00:00
|
|
|
}
|
|
|
|
}
|