μ—°νƒ€κ²Œμž„ proof of concept


using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class r35_SmashGameTest : MonoBehaviour
{
public float smashMax = 120f;
public float smashHit = 3;
public float smashLose = 1.2f;

public float smashGauge = 0;
public Image smashFill;

private Coroutine smashGame;

// Start is called before the first frame update
void Start()
{
smashGame = StartCoroutine(_SmashGame());
}

private bool doingSmash = false;

private void LateUpdate()
{
if (doingSmash)
{
if (Input.GetMouseButtonDown(0))
{
smashGauge += smashHit;
}

if (smashGauge < 0) smashGauge = 0;
smashFill.fillAmount = smashGauge / smashMax;

if (smashGauge >= smashMax)
{
doingSmash = false;
StopCoroutine(smashGame);
}
}
}

IEnumerator _SmashGame()
{
doingSmash = true;
while (true)
{
smashGauge -= smashLose;
yield return new WaitForSeconds(0.05f);
}
}
}