mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 15:18:25 -05:00
71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityEngine;
|
|
|
|
namespace GolfControls
|
|
{
|
|
public class PowerController : MonoBehaviour
|
|
{
|
|
public FloatVariable powerVariable;
|
|
public BoolVariable isPausedVariable;
|
|
|
|
[SerializeField] private float timeToMaxPower = 1.0f;
|
|
[SerializeField] private float pauseTimeAtEnds = 0.05f;
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(SlidePower());
|
|
}
|
|
|
|
|
|
private IEnumerator SlidePower()
|
|
{
|
|
float timer = 0;
|
|
|
|
bool goingUp = true;
|
|
float timerGoal = timeToMaxPower;
|
|
|
|
while (true)
|
|
{
|
|
while (isPausedVariable.Value) yield return null;
|
|
|
|
yield return null;
|
|
|
|
timer += Time.deltaTime;
|
|
float percentTime = timer / timerGoal;
|
|
|
|
float outputPercent = goingUp ? percentTime : 1.0f - percentTime;
|
|
|
|
powerVariable.SetValue(outputPercent);
|
|
|
|
if (percentTime < 1.0f) continue;
|
|
|
|
//Bounce back starts here
|
|
|
|
percentTime = 1.0f;
|
|
outputPercent = goingUp ? percentTime : 1.0f - percentTime;
|
|
powerVariable.SetValue(outputPercent);
|
|
|
|
float pauseTimer = 0.0f;
|
|
while (pauseTimer < pauseTimeAtEnds)
|
|
{
|
|
|
|
while (isPausedVariable.Value) yield return null;
|
|
|
|
yield return null;
|
|
pauseTimer += Time.deltaTime;
|
|
}
|
|
|
|
SwapDirection();
|
|
}
|
|
|
|
void SwapDirection()
|
|
{
|
|
goingUp = !goingUp;
|
|
timer = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|