2024-04-24 11:02:50 -04:00
|
|
|
using System;
|
2024-04-15 21:45:10 -04:00
|
|
|
using UnityAtoms.BaseAtoms;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2024-04-24 11:02:50 -04:00
|
|
|
namespace MAVRIC.GEEKCup.GolfControls
|
2024-04-15 21:45:10 -04:00
|
|
|
{
|
|
|
|
public class StrokeCounter : MonoBehaviour
|
|
|
|
{
|
|
|
|
public IntVariable StrokeVariable;
|
2024-04-24 11:02:50 -04:00
|
|
|
|
|
|
|
public BoolEvent IsIncrementedEvent;
|
|
|
|
public int ParStrokeCount = 5;
|
|
|
|
|
|
|
|
public VoidEvent LossEvent;
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
{
|
|
|
|
IsIncrementedEvent.Register(OnStrokeCountIncremented);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
IsIncrementedEvent.Unregister(OnStrokeCountIncremented);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-22 13:40:07 -04:00
|
|
|
public void OnHit(bool isHit)
|
2024-04-15 21:45:10 -04:00
|
|
|
{
|
2024-04-22 13:40:07 -04:00
|
|
|
if (!isHit)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StrokeVariable.SetValue(StrokeVariable.Value + 1);
|
2024-04-15 21:45:10 -04:00
|
|
|
}
|
2024-04-24 11:02:50 -04:00
|
|
|
|
|
|
|
|
|
|
|
private void OnStrokeCountIncremented(bool ballStartedHit)
|
|
|
|
{
|
|
|
|
if (ballStartedHit) return;
|
|
|
|
|
|
|
|
if (StrokeVariable.Value >= ParStrokeCount)
|
|
|
|
{
|
|
|
|
LossEvent.Raise();
|
|
|
|
}
|
|
|
|
}
|
2024-04-15 21:45:10 -04:00
|
|
|
}
|
|
|
|
}
|