A completely working minigame Insert Keys, Added SFX + Light, Still not mergable - needs dev team check
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using NUnit.Framework.Constraints;
|
||||
using UnityEngine;
|
||||
|
||||
public class Key : MonoBehaviour
|
||||
@@ -7,29 +7,34 @@ public class Key : MonoBehaviour
|
||||
public bool isSelected = false;
|
||||
public Vector3 insertedRotation;
|
||||
public Vector3 insertedOffset;
|
||||
public Vector3 wiggleOffset = new Vector3(0, 0, 10);
|
||||
public float lockoutDuration = 3;
|
||||
public InserKeysMinigameManager manager;
|
||||
|
||||
public Vector3 wiggleOffset = new Vector3(0, 0, 10);
|
||||
public Vector3 winRotation = new Vector3(0, 0, 180);
|
||||
private Vector3 startPosition;
|
||||
private Vector3 startRotation;
|
||||
|
||||
public float WinRotDuration = 1.0f;
|
||||
public float lockoutDuration = 3;
|
||||
|
||||
public GameObject winText;
|
||||
public AudioSource lockSound;
|
||||
public InserKeysMinigameManager manager;
|
||||
private Light keyLight;
|
||||
void Start()
|
||||
{
|
||||
startPosition = transform.parent.position;
|
||||
startRotation = transform.parent.eulerAngles;
|
||||
startPosition = transform.position;
|
||||
startRotation = transform.eulerAngles;
|
||||
keyLight = GetComponentInChildren<Light>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if (manager.isInputLocked) return;
|
||||
|
||||
isSelected = true;
|
||||
keyLight.enabled = true;
|
||||
Debug.Log("Key tapped - isSelected is now: " + isSelected);
|
||||
}
|
||||
|
||||
@@ -37,22 +42,47 @@ public class Key : MonoBehaviour
|
||||
{
|
||||
manager.isInputLocked = true;
|
||||
|
||||
Vector3 baseRot = transform.parent.eulerAngles;
|
||||
Vector3 baseRot = transform.eulerAngles;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
transform.parent.eulerAngles = baseRot + wiggleOffset;
|
||||
yield return new WaitForSeconds(0.08f);
|
||||
transform.parent.eulerAngles = baseRot - wiggleOffset;
|
||||
yield return new WaitForSeconds(0.08f);
|
||||
transform.eulerAngles = baseRot + wiggleOffset;
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
transform.eulerAngles = baseRot - wiggleOffset;
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
}
|
||||
transform.parent.eulerAngles = baseRot;
|
||||
transform.eulerAngles = baseRot;
|
||||
|
||||
yield return new WaitForSeconds(lockoutDuration - 0.48f);
|
||||
|
||||
transform.parent.position = startPosition;
|
||||
transform.parent.eulerAngles = startRotation;
|
||||
transform.position = startPosition;
|
||||
transform.eulerAngles = startRotation;
|
||||
isSelected = false;
|
||||
|
||||
keyLight.enabled = false;
|
||||
manager.isInputLocked = false;
|
||||
}
|
||||
|
||||
public IEnumerator HandleWin()
|
||||
{
|
||||
manager.isInputLocked = true;
|
||||
if (lockSound != null) lockSound.Play();
|
||||
|
||||
Vector3 startRot = transform.eulerAngles;
|
||||
Vector3 endRot = startRot + winRotation;
|
||||
float elapsed = 0f;
|
||||
|
||||
while (elapsed < WinRotDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
float t = elapsed / WinRotDuration;
|
||||
transform.eulerAngles = Vector3.Lerp(startRot, endRot, t);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.eulerAngles = endRot;
|
||||
|
||||
Debug.Log("You win");
|
||||
if (winText != null) winText.SetActive(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user