mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 15:18:25 -05:00
49 lines
1.0 KiB
C#
49 lines
1.0 KiB
C#
using System;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityEngine;
|
|
|
|
namespace MAVRIC.GEEKCup.GolfControls
|
|
{
|
|
public class StrokeCounter : MonoBehaviour
|
|
{
|
|
public IntVariable StrokeVariable;
|
|
|
|
public BoolEvent IsIncrementedEvent;
|
|
public int ParStrokeCount = 5;
|
|
|
|
public VoidEvent LossEvent;
|
|
|
|
private void OnEnable()
|
|
{
|
|
IsIncrementedEvent.Register(OnStrokeCountIncremented);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
IsIncrementedEvent.Unregister(OnStrokeCountIncremented);
|
|
}
|
|
|
|
|
|
public void OnHit(bool isHit)
|
|
{
|
|
if (!isHit)
|
|
{
|
|
return;
|
|
}
|
|
|
|
StrokeVariable.SetValue(StrokeVariable.Value + 1);
|
|
}
|
|
|
|
|
|
private void OnStrokeCountIncremented(bool ballStartedHit)
|
|
{
|
|
if (ballStartedHit) return;
|
|
|
|
if (StrokeVariable.Value >= ParStrokeCount)
|
|
{
|
|
LossEvent.Raise();
|
|
}
|
|
}
|
|
}
|
|
}
|