private IEnumerator RepairExpireTimer(difficultyLevel diff, float timer) { if (playerCoroutine == null) { playerCoroutine = StartCoroutine(PlayerCoroutine(diff)); } if (npcCoroutine == null) { npcCoroutine = StartCoroutine(NPCCoroutine(diff)); } yield return(new WaitForSeconds(timer)); if (playerCoroutine != null) { StopCoroutine(playerCoroutine); } if (npcCoroutine != null) { StopCoroutine(npcCoroutine); } if (completed == false) { OnRepaired?.Invoke(false); } repairGameobject.SetActive(false); }
private IEnumerator NPCCoroutine(difficultyLevel diff) { SetDifficulty(diff); while (progress != WinValue) { float rate = UnityEngine.Random.Range(npcMinRefreshTime, npcMaxRefreshTime) / 2; npcRB.gravityScale = 0; yield return(new WaitForSeconds(rate)); npcRB.gravityScale = 1; yield return(new WaitForSeconds(rate)); npcRB.gravityScale = 5; npcRB.AddForce(new Vector2(0, 1) * npcPower, ForceMode2D.Impulse); } if (timerCoroutine != null) { StopCoroutine(timerCoroutine); timerCoroutine = null; } completed = true; OnRepaired?.Invoke(true); repairGameobject.SetActive(false); }