Almost comletely working minigame, but still in progress, code almost done
This commit is contained in:
58
Assets/KeyInsertMinigameAssets/Scripts/Key.cs
Normal file
58
Assets/KeyInsertMinigameAssets/Scripts/Key.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user