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(); } } }
private void OnSpamButtonPressed() { player.audioSource.PlayOneShot(spamSound); fillImage.fillAmount += increaseValue; fillImage.color = Color.Lerp(minAmountColor, maxAmountColor, fillImage.fillAmount); buttonPromptRectTransform.localScale = Vector3.one * onPressScaleFactor; // Player filled the image and won the minigame if (fillImage.fillAmount >= 1.0f) { player.audioSource.PlayOneShot(successSound); OnMinigameSuccess.Invoke(); } }
private void OnNewDirectionPressed(UnityEngine.InputSystem.InputAction.CallbackContext context) { Vector2 currentDir = context.ReadValue <Vector2>(); currentDir.Normalize(); float signedAngle = Vector3.SignedAngle(lastDir, currentDir, -Vector3.forward); doneDegree += signedAngle; float percentage = doneDegree / neededDegree; fillImage.fillAmount = percentage; fillImage.color = Color.Lerp(minAmountColor, maxAmountColor, percentage); if (doneDegree >= neededDegree) { player.audioSource.PlayOneShot(successSound); OnMinigameSuccess.Invoke(); } lastDir = currentDir; }