Almost comletely working minigame, but still in progress, code almost done

This commit is contained in:
2026-05-08 10:20:22 +02:00
parent 8948cbdb14
commit 2f86bab336
6 changed files with 219 additions and 3 deletions

View File

@@ -0,0 +1,18 @@
using UnityEngine;
public class InserKeysMinigameManager : MonoBehaviour
{
public int correctIndex;
public bool isInputLocked = false;
private void Start()
{
correctIndex = Random.Range(0, 9);
Debug.Log("The correct keyhole is: " + correctIndex);
}
public bool CheckKeyHole(int index)
{
return index == correctIndex;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3cd9b947f2376eb4da79d8910a5b588e

View File

@@ -0,0 +1,58 @@
using System.Collections;
using UnityEditor;
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 float lockoutDuration = 3;
public InserKeysMinigameManager manager;
private Vector3 startPosition;
private Vector3 startRotation;
void Start()
{
startPosition = transform.parent.position;
startRotation = transform.parent.eulerAngles;
}
void Update()
{
}
void OnMouseDown()
{
if (manager.isInputLocked) return;
isSelected = true;
Debug.Log("Key tapped - isSelected is now: " + isSelected);
}
public IEnumerator HandleWrongAttempt()
{
manager.isInputLocked = true;
Vector3 baseRot = transform.parent.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.parent.eulerAngles = baseRot;
yield return new WaitForSeconds(lockoutDuration - 0.48f);
transform.parent.position = startPosition;
transform.parent.eulerAngles = startRotation;
isSelected = false;
manager.isInputLocked = false;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4aae5484fa5ce7d42a5ab54ccd82bc19

View File

@@ -3,6 +3,8 @@ using UnityEngine;
public class KeyHole : MonoBehaviour
{
public int index;
public Key key;
public InserKeysMinigameManager manager;
void Start()
{
@@ -15,9 +17,28 @@ public class KeyHole : MonoBehaviour
}
private void OnMouseDown()
void OnMouseDown()
{
Debug.Log("KeyHole " + index + " was tapped!");
if (manager.isInputLocked) return;
Debug.Log("Keyhole " + index + " was tapped.");
if (key.isSelected)
{
key.transform.parent.position = transform.position + key.insertedOffset;
key.transform.parent.eulerAngles = key.insertedRotation;
Debug.Log("Key teleported to keyhole " + index);
if (manager.CheckKeyHole(index))
{
Debug.Log("Correct, You Win");
}
else
{
Debug.Log("Wrong");
key.StartCoroutine(key.HandleWrongAttempt());
}
}
}
}