89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System.Collections;
|
|
using NUnit.Framework.Constraints;
|
|
using UnityEngine;
|
|
|
|
public class Key : MonoBehaviour
|
|
{
|
|
public bool isSelected = false;
|
|
public Vector3 insertedRotation;
|
|
public Vector3 insertedOffset;
|
|
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.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);
|
|
}
|
|
|
|
public IEnumerator HandleWrongAttempt()
|
|
{
|
|
manager.isInputLocked = true;
|
|
|
|
Vector3 baseRot = transform.eulerAngles;
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
transform.eulerAngles = baseRot + wiggleOffset;
|
|
yield return new WaitForSeconds(0.1f);
|
|
transform.eulerAngles = baseRot - wiggleOffset;
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
transform.eulerAngles = baseRot;
|
|
|
|
yield return new WaitForSeconds(lockoutDuration - 0.48f);
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
|