Almost comletely working minigame, but still in progress, code almost done
This commit is contained in:
18
Assets/KeyInsertMinigameAssets/Scripts/InserKeysManager.cs
Normal file
18
Assets/KeyInsertMinigameAssets/Scripts/InserKeysManager.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cd9b947f2376eb4da79d8910a5b588e
|
||||
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;
|
||||
}
|
||||
}
|
||||
2
Assets/KeyInsertMinigameAssets/Scripts/Key.cs.meta
Normal file
2
Assets/KeyInsertMinigameAssets/Scripts/Key.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aae5484fa5ce7d42a5ab54ccd82bc19
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,6 +311,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 6
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &201444427
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -611,6 +613,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 3
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &530549045
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -650,6 +654,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 2
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &672204613
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -758,6 +764,52 @@ PrefabInstance:
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 739154329}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 3cb302613fc70fa48b0d1ab0b0783be5, type: 3}
|
||||
--- !u!1 &736315737
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 736315739}
|
||||
- component: {fileID: 736315738}
|
||||
m_Layer: 0
|
||||
m_Name: InserKeysManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &736315738
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 736315737}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 3cd9b947f2376eb4da79d8910a5b588e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::InserKeysMinigameManager
|
||||
correctIndex: 0
|
||||
isInputLocked: 0
|
||||
--- !u!4 &736315739
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 736315737}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 943.20435, y: 1092.0742, z: -294.71655}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &739154325 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: -5568371526223589888, guid: 3cb302613fc70fa48b0d1ab0b0783be5, type: 3}
|
||||
@@ -776,6 +828,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 1
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &739154330
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -797,6 +851,50 @@ BoxCollider:
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 0.015721833, y: 0.015728435, z: 0.013296423}
|
||||
m_Center: {x: -0.00000001490116, y: -0.000000008847572, z: 0.00000001792796}
|
||||
--- !u!1 &848229114 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: -7453297586425830842, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
m_PrefabInstance: {fileID: 1269638069}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!65 &848229118
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 848229114}
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_IsTrigger: 0
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 0.019107988, y: 0.0021404205, z: 0.009510478}
|
||||
m_Center: {x: 0.0088456655, y: 0.0000072948333, z: 0.0014001705}
|
||||
--- !u!114 &848229119
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 848229114}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 4aae5484fa5ce7d42a5ab54ccd82bc19, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Key
|
||||
isSelected: 0
|
||||
insertedRotation: {x: 270, y: 180, z: 270}
|
||||
insertedOffset: {x: 460, y: -150, z: 0}
|
||||
wiggleOffset: {x: 0, y: 0, z: 0}
|
||||
lockoutDuration: 3
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!4 &907505012 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
@@ -820,6 +918,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 7
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &914661684
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -946,6 +1046,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 8
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &1035961571
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1119,7 +1221,13 @@ PrefabInstance:
|
||||
- {fileID: 65702495048144492, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
- {fileID: 3256796887105840307, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_AddedComponents:
|
||||
- targetCorrespondingSourceObject: {fileID: -7453297586425830842, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 848229119}
|
||||
- targetCorrespondingSourceObject: {fileID: -7453297586425830842, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
insertIndex: -1
|
||||
addedObject: {fileID: 848229118}
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 56e0065a74e418b4fb1e4e7d2236b645, type: 3}
|
||||
--- !u!1 &1306081367 stripped
|
||||
GameObject:
|
||||
@@ -1139,6 +1247,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 4
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &1306081372
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1393,6 +1503,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 0
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &1706075445
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1601,6 +1713,8 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier: Assembly-CSharp::KeyHole
|
||||
index: 5
|
||||
key: {fileID: 848229119}
|
||||
manager: {fileID: 736315738}
|
||||
--- !u!65 &1943575596
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1709,3 +1823,4 @@ SceneRoots:
|
||||
- {fileID: 191909596}
|
||||
- {fileID: 425617997}
|
||||
- {fileID: 1373860631}
|
||||
- {fileID: 736315739}
|
||||
|
||||
Reference in New Issue
Block a user