Added spring
This commit is contained in:
@@ -3,11 +3,37 @@ using System;
|
||||
|
||||
namespace Fruitomation.Game
|
||||
{
|
||||
public enum TriggerType
|
||||
{
|
||||
Enter,
|
||||
Stay
|
||||
}
|
||||
|
||||
public class TriggerDetector : MonoBehaviour
|
||||
{
|
||||
private Action<Collider2D> RegisteredAction;
|
||||
private Action<Collider2D> RegisteredActionStay;
|
||||
private Action<Collider2D> RegisteredActionEnter;
|
||||
|
||||
public void SetAction(Action<Collider2D> action) => RegisteredAction = action;
|
||||
private void OnTriggerStay2D(Collider2D other) => RegisteredAction?.Invoke(other);
|
||||
private TriggerType Type;
|
||||
|
||||
public void SetAction(Action<Collider2D> action, TriggerType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TriggerType.Stay:
|
||||
RegisteredActionStay = action;
|
||||
return;
|
||||
|
||||
case TriggerType.Enter:
|
||||
RegisteredActionEnter = action;
|
||||
return;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) => RegisteredActionEnter?.Invoke(other);
|
||||
private void OnTriggerStay2D(Collider2D other) => RegisteredActionStay?.Invoke(other);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user