private void OnQTEButtonPressed(int buttonIndex) { if (firstFrame) { return; } // Pressed right button if (buttonCombination[currentIndex] == buttonIndex) { Color currentColor = buttonObjects[currentIndex].GetComponent <Image>().color; Color finishedColor = Color.white * currentColor; finishedColor.a = 0.5f; buttonObjects[currentIndex].GetComponent <Image>().color = finishedColor; currentIndex++; if (currentIndex == buttonCombination.Count) { player.audioSource.PlayOneShot(successSound); OnMinigameSuccess.Invoke(); } else { player.audioSource.PlayOneShot(correctSound); } } // Pressed wrong button else { player.audioSource.PlayOneShot(failSound); OnMinigameFail.Invoke(); } }
protected override void Update() { // Check if a new projectile should be spawned float currentTime = Time.time - startTime; if (spawntimes.Count > 0 && currentTime >= spawntimes.Peek()) { Debug.Log("Spawn new projectile"); spawntimes.Dequeue(); GameObject projectileGameObject = new GameObject("Projectile" + activeProjectiles.Count); RectTransform projectileRectTransform = projectileGameObject.AddComponent <RectTransform>(); Image spriteImage = projectileGameObject.AddComponent <Image>(); spriteImage.sprite = squareSprite; spriteImage.color = Color.red; projectileRectTransform.sizeDelta = new Vector2(10, minigameScreen.sizeDelta.y); projectileRectTransform.anchorMax = Vector2.zero; projectileRectTransform.anchorMin = Vector2.zero; projectileRectTransform.SetParent(minigameScreen); projectileRectTransform.localPosition = Vector3.zero; projectileRectTransform.localScale = Vector3.one; projectileRectTransform.localRotation = Quaternion.identity; projectileRectTransform.anchoredPosition = new Vector2(minigameScreen.sizeDelta.x - projectileRectTransform.sizeDelta.x / 2, minigameScreen.sizeDelta.y * 0.5f); activeProjectiles.Add(projectileRectTransform); } List <RectTransform> projectilesToDestroy = new List <RectTransform>(); foreach (RectTransform projectile in activeProjectiles) { projectile.Translate(-1 * speedFactor, 0, 0, Space.Self); // Projectile is out of sight and can be destroyed if (projectile.anchoredPosition.x < projectile.sizeDelta.x / 2.0f) { player.audioSource.PlayOneShot(failSound); OnMinigameFail.Invoke(); return; } } // Lost because all projectiles got destroyed if (activeProjectiles.Count == 0 && spawntimes.Count == 0) { Debug.Log("Hit: " + hitProjectiles + " Count: " + projectileCount); if (projectileCount == hitProjectiles) { Debug.Log("Won"); player.audioSource.PlayOneShot(successSound); OnMinigameSuccess.Invoke(); } else { Debug.Log("Failed"); player.audioSource.PlayOneShot(failSound); OnMinigameFail.Invoke(); } } }
public static void MinigameFinished(bool success) { if (success) { OnMinigameWin?.Invoke(); } else { OnMinigameFail?.Invoke(); } }
protected override void Update() { if (fillImage == null) { return; } fillImage.fillAmount -= decreaseValue * Time.deltaTime; fillImage.color = Color.Lerp(minAmountColor, maxAmountColor, fillImage.fillAmount); // Player lost the game because the fillamount reached zero if (fillImage.fillAmount <= 0.0f) { player.audioSource.PlayOneShot(failSound); OnMinigameFail.Invoke(); } }
protected override void Update() { Vector3 anchoredPosition = new Vector2(minigameScreen.sizeDelta.x * 0.5f, minigameScreen.sizeDelta.y * 0.5f); anchoredPosition += lastDir * offsetFactor; buttonPromptRectTransform.anchoredPosition = anchoredPosition; spinningImageRectTransform.Rotate(0, 0, -rotationSpeed * Time.deltaTime, Space.Self); doneDegree -= decreaseValue * Time.deltaTime; float percentage = doneDegree / neededDegree; fillImage.fillAmount = percentage; fillImage.color = Color.Lerp(minAmountColor, maxAmountColor, percentage); // Player lost the game because the fillamount reached zero if (fillImage.fillAmount <= 0.0f) { player.audioSource.PlayOneShot(failSound); OnMinigameFail.Invoke(); } }
public void OnTriggerButtonPressed() { buttonPromptRectTransform.localScale = Vector3.one * onPressScaleFactor; // Check if projectile is in target if (activeProjectiles.Count > 0 && activeProjectiles[0].anchoredPosition.x >= hitboxOffset && activeProjectiles[0].anchoredPosition.x <= hitboxSize + hitboxOffset) { RectTransform hitProjectile = activeProjectiles[0]; activeProjectiles.Remove(hitProjectile); UnityEngine.Object.Destroy(hitProjectile.gameObject); hitProjectiles++; player.audioSource.PlayOneShot(correctSound); Debug.Log("Hit projectile"); } else { Debug.Log("Missed projectile"); OnMinigameFail.Invoke(); } }