diff --git a/UnityGoesBruh/Assets/Animations/Simon Say/Simon Say.controller b/UnityGoesBruh/Assets/Animations/Simon Say/Simon Say.controller index df6e21753f4c995f2b86b0cadba437073809a765..a83028442768361725b92c870116fc8ec52d07a1 100644 --- a/UnityGoesBruh/Assets/Animations/Simon Say/Simon Say.controller +++ b/UnityGoesBruh/Assets/Animations/Simon Say/Simon Say.controller @@ -119,9 +119,9 @@ AnimatorStateTransition: m_Mute: 0 m_IsExit: 0 serializedVersion: 3 - m_TransitionDuration: 0 + m_TransitionDuration: 0.82612747 m_TransitionOffset: 0 - m_ExitTime: 0.0000000065540076 + m_ExitTime: 0.0000000059964536 m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 diff --git a/UnityGoesBruh/Assets/Scripts/Game/Logic.cs b/UnityGoesBruh/Assets/Scripts/Game/Logic.cs index 8f864296fe1f5f9c946249edcdeb85e7bc4c88f2..01d303bc3898927c38df874132928f14ebd85003 100644 --- a/UnityGoesBruh/Assets/Scripts/Game/Logic.cs +++ b/UnityGoesBruh/Assets/Scripts/Game/Logic.cs @@ -23,18 +23,21 @@ public class Logic : MonoBehaviour, MiniGameObserver } + //Choose a new random game on win public void OnWin(MiniGame miniGame) { _curMiniGame.enabled = false; ChooseRandomMiniGame(); } + //Not implemented public void OnLose(MiniGame miniGame) { _curMiniGame.enabled = false; //Quit Game / Lose Condition } + //Choose the new randomGame private void ChooseRandomMiniGame() { _curMiniGame = _miniGames[Random.Range(0, _miniGames.Length)].GetComponent<MiniGame>(); diff --git a/UnityGoesBruh/Assets/Scripts/Game/MiniGameObserver.cs b/UnityGoesBruh/Assets/Scripts/Game/MiniGameObserver.cs index b5c4f12941dcd970da2c82beba2713c4c62ece00..518c459f9d21e1785c9c9278b032ef2d095f7f7d 100644 --- a/UnityGoesBruh/Assets/Scripts/Game/MiniGameObserver.cs +++ b/UnityGoesBruh/Assets/Scripts/Game/MiniGameObserver.cs @@ -4,6 +4,7 @@ using UnityEngine; public interface MiniGameObserver { + //Observer interface void OnWin(MiniGame miniGame); void OnLose(MiniGame miniGame); } diff --git a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/Keypad.cs b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/Keypad.cs index 90d100fff24da7026fdc795aa83a9d8420576b34..0a2a85db0bd2d478fecfaf0f72a5f825c4110201 100644 --- a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/Keypad.cs +++ b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/Keypad.cs @@ -19,21 +19,24 @@ namespace Game.MinigameScript { _keypadController = gameObject.GetComponent<keypadController>(); _keypadController.OnCorrect(OnWin); - _quiz = new Dictionary<string, int>(); - _quiz.Add("Début de la première guerre mondial", 1914); - _quiz.Add("Fin de la première guerre mondial", 1918); - _quiz.Add("Début de la deuxième guerre mondial", 1939); - _quiz.Add("Fin de la deuxième guerre mondial", 1945); - _quiz.Add("154 * 10 - 457", 1083); - _quiz.Add("2^10", 1024); - _quiz.Add("Réponse à la vie", 42); - _quiz.Add("Combien de Fast and Furious sont sortie\n1: 9\n2: 12\n3: 11", 2); - _quiz.Add("Qui est caroline dans Portal2\n1: Le petit robot qui nous accompagne\n2: Le personnage principal\n3: L'assistant personnel du PDG de Aperture Science", 3); - _quiz.Add("Date de sortie du premier Mario\n1: 1983\n2: 1991\n3: 1985", 1); - _quiz.Add("Quand est sortie le premier fps\n1: 1974\n2: 1993\n3: 1996", 1); - _quiz.Add("Quand est sortie la première version de l'editeur Unity", 2005); + _quiz = new Dictionary<string, int> + { + { "Début de la première guerre mondial", 1914 }, + { "Fin de la première guerre mondial", 1918 }, + { "Début de la deuxième guerre mondial", 1939 }, + { "Fin de la deuxième guerre mondial", 1945 }, + { "154 * 10 - 457", 1083 }, + { "2^10", 1024 }, + { "Réponse à la vie", 42 }, + { "Combien de Fast and Furious sont sortie\n1: 9\n2: 12\n3: 11", 2 }, + { "Qui est caroline dans Portal2\n1: Le petit robot qui nous accompagne\n2: Le personnage principal\n3: L'assistant personnel du PDG de Aperture Science", 3 }, + { "Date de sortie du premier Mario\n1: 1983\n2: 1991\n3: 1985", 1 }, + { "Quand est sortie le premier fps\n1: 1974\n2: 1993\n3: 1996", 1 }, + { "Quand est sortie la première version de l'editeur Unity", 2005 } + }; } + //Function called to "init" the game public override void StartScript() { KeyValuePair<String, int> question = _quiz.ElementAt(Random.Range(0, _quiz.Count)); @@ -42,6 +45,7 @@ namespace Game.MinigameScript _tmpText.text = question.Key; } + //Function called when the game is won public override void OnWin() { _keypadController.enabled = false; @@ -49,6 +53,7 @@ namespace Game.MinigameScript NotifyWin(); } + //Function called when the game is lost public override void OnLose() { NotifyLose(); diff --git a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/MiniGame.cs b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/MiniGame.cs index 9c7417c1f01ea9f2dba06452547f2d924927ed62..eea6c36ab7adf23697ebf5854516f33eaf075e41 100644 --- a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/MiniGame.cs +++ b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/MiniGame.cs @@ -4,8 +4,8 @@ using UnityEngine; public abstract class MiniGame : MonoBehaviour { + //The class that all minigame use private List<MiniGameObserver> _observers = new List<MiniGameObserver>(); - // Start is called before the first frame update public void AddObserver(MiniGameObserver miniGameObserver) { diff --git a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/SimonSay.cs b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/SimonSay.cs index 11d83501a24cb4949b3094fabbf427a50f7b91f3..81a197367dbbd16df21b61e1911cf70cd80956b4 100644 --- a/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/SimonSay.cs +++ b/UnityGoesBruh/Assets/Scripts/Game/MinigameScript/SimonSay.cs @@ -4,6 +4,7 @@ namespace Game.MinigameScript { public class SimonSay : MiniGame { + //The simonSay minigame private SimonSayController _simonSayController; private void Start() diff --git a/UnityGoesBruh/Assets/Scripts/HoldInteraction.cs b/UnityGoesBruh/Assets/Scripts/HoldInteraction.cs index 93f748d0d2bed31c491702a8c7a4492963d15165..feab8ba1a4fdd58ee29660d18c7bcd920074b04d 100644 --- a/UnityGoesBruh/Assets/Scripts/HoldInteraction.cs +++ b/UnityGoesBruh/Assets/Scripts/HoldInteraction.cs @@ -15,6 +15,7 @@ public class HoldInteraction : Interactable } + //A class to tell that the object can be hold public override GameObject Interact() { return this.gameObject; diff --git a/UnityGoesBruh/Assets/Scripts/Interactable.cs b/UnityGoesBruh/Assets/Scripts/Interactable.cs index 0ac4002d0610683c61f1a57d20bf080b89bc342d..857bc3df77d8e2705492525c9517cd54d614b44b 100644 --- a/UnityGoesBruh/Assets/Scripts/Interactable.cs +++ b/UnityGoesBruh/Assets/Scripts/Interactable.cs @@ -5,6 +5,9 @@ using UnityEngine; public abstract class Interactable: MonoBehaviour { + //The interface for the interactable object + + //The nortified Observers in case we need private List<Action<string>> _observers = new List<Action<string>>(); public abstract GameObject Interact(); diff --git a/UnityGoesBruh/Assets/Scripts/Keypad/ButtonInteractable.cs b/UnityGoesBruh/Assets/Scripts/Keypad/ButtonInteractable.cs index 33a375c2918e58c4e18fa6033eca467c78cf8f8b..3d521fddf27759073a35fdedf7e7fb50eeb75f51 100644 --- a/UnityGoesBruh/Assets/Scripts/Keypad/ButtonInteractable.cs +++ b/UnityGoesBruh/Assets/Scripts/Keypad/ButtonInteractable.cs @@ -18,6 +18,7 @@ public class ButtonInteractable : Interactable } + //The interaction on press of one of the 12 buttons public override GameObject Interact() { if (_animator != null) { diff --git a/UnityGoesBruh/Assets/Scripts/Keypad/keypadController.cs b/UnityGoesBruh/Assets/Scripts/Keypad/keypadController.cs index 232f58d86ce2bcfb5e5c857dd3e26a4d73a2dfdf..b342d3c4e60046c6cb4776d8ed8aa54fa7076cb3 100644 --- a/UnityGoesBruh/Assets/Scripts/Keypad/keypadController.cs +++ b/UnityGoesBruh/Assets/Scripts/Keypad/keypadController.cs @@ -21,6 +21,7 @@ public class keypadController : MonoBehaviour // Start is called before the first frame update void Start() { + //Add self as observer to all buttons foreach (var button in _buttons) { button.GetComponent<ButtonInteractable>().AddObserver(OnButtonPressed); @@ -35,16 +36,19 @@ public class keypadController : MonoBehaviour } + //Event used when the keypad code is correct public void OnCorrect(Action onCorrect) { this.onCorrect = onCorrect; } + //Check if the code is correct, used coroutine for display void OnButtonPressed(string buttonName) { StartCoroutine(checkInput(buttonName)); } + //Check the input code and display a message if correct or not IEnumerator checkInput(string buttonName) { if (_textMeshProText.text.Length < 4 && buttonName != "C" && buttonName != "V") diff --git a/UnityGoesBruh/Assets/Scripts/Player/InteractionController.cs b/UnityGoesBruh/Assets/Scripts/Player/InteractionController.cs index 593f8351e0568f1235a88efaef562520c1622ee2..27783d9b37faff7b1efca3d20551b17c57e87092 100644 --- a/UnityGoesBruh/Assets/Scripts/Player/InteractionController.cs +++ b/UnityGoesBruh/Assets/Scripts/Player/InteractionController.cs @@ -24,12 +24,14 @@ public class InteractionController : MonoBehaviour // Start is called before the first frame update void Start() { + //Get the camera and the two layer that is usefull _camera = this.GetComponent<Camera>(); _layer = LayerMask.NameToLayer("Interactable"); _noCollidWithPlayerLayer = LayerMask.NameToLayer("NoCollidWithPlayer"); _textMeshProText = _cursor.GetComponent<TMP_Text>(); } + // Drop the current holded object void DropCurrentObject() { _currentHoldedObjectRigidbody.freezeRotation = false; @@ -41,22 +43,28 @@ public class InteractionController : MonoBehaviour // Update is called once per frame void Update() { + //Drop the current Object if you are too far if (_currentHoldedObject != null && Vector3.Distance(this.transform.position, _currentHoldedObject.transform.position) > 5) { - + DropCurrentObject(); } + //Drop the current Object if 'E' is pressed if (_currentHoldedObject != null && Input.GetKeyDown(KeyCode.E)) { DropCurrentObject(); } - if(!_justDropped){ + //Raycast too get the object in front of the player, avoid raycasting if the object is dropped in this frame + if (!_justDropped){ Ray ray = _camera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); RaycastHit hit; if (Physics.Raycast(ray, out hit, _interactionDistance)) { + //Check the two valid layer if (hit.collider.gameObject.layer == _layer || hit.collider.gameObject.layer == _noCollidWithPlayerLayer) { + //Cursor to yellow _textMeshProText.color = Color.yellow; - if (Input.GetKeyDown(KeyCode.E)) + //Get the object + if (Input.GetKeyDown(KeyCode.E)) { Interactable i = hit.collider.gameObject.GetComponent<Interactable>(); GameObject gameObject = i.Interact(); @@ -79,6 +87,7 @@ public class InteractionController : MonoBehaviour if (_currentHoldedObject != null) { Vector3 directionVector = _camera.transform.position + _camera.transform.forward * 2f - _currentHoldedObject.transform.position; + //Thank you for this line _currentHoldedObjectRigidbody.velocity = directionVector * 1000f * Time.deltaTime; _currentHoldedObjectRigidbody.useGravity = false; _currentHoldedObjectRigidbody.freezeRotation = true; diff --git a/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayController.cs b/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayController.cs index b26e55164839bc75113d1dbd337fc71426e3efe8..e0bda325cc3aba862c1f8bcb7e450a0aef49e6f6 100644 --- a/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayController.cs +++ b/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayController.cs @@ -18,6 +18,8 @@ public class SimonSayController : MonoBehaviour private List<string> _orders = new List<string>(); private List<string> _currentInput = new List<string>(); + + private bool _isPlayingOrder = false; // Start is called before the first frame update void Start() { @@ -33,19 +35,25 @@ public class SimonSayController : MonoBehaviour } + //Event used when one of the three color is pressed void OnButtonPressed(string buttonName) { - StartCoroutine(checkInput(buttonName)); + if (!_isPlayingOrder) { + StartCoroutine(checkInput(buttonName)); + } } + //Reset the symon say game public void Reset() { _orders.Clear(); _currentInput.Clear(); } + //Play the animation that tell the order to the player IEnumerator PlayOrders() { + _isPlayingOrder = true; foreach (var order in _orders) { foreach (var button in _buttons) @@ -57,22 +65,21 @@ public class SimonSayController : MonoBehaviour } } } + _isPlayingOrder = false; } + //Check if the user correctly prompted the order, player the order in case of failure, if the player win, call the onSuccess action IEnumerator checkInput(string buttonName) { _currentInput.Add(buttonName); if (_currentInput.Count >= _orders.Count) { bool error = false; - for (int i = 0; i < _orders.Count; i++) + for (int i = 0; i < _orders.Count && !error; i++) { - if (_currentInput[i] != _orders[i]) - { - error = true; - yield break; - } + error = (_currentInput[i] != _orders[i]); } + Debug.Log(error); if (!error) { if(_numberOfRound == _currentInput.Count) @@ -88,11 +95,13 @@ public class SimonSayController : MonoBehaviour } } + //The function that is called when the player win public void OnSuccess(Action onSuccess) { this.onSuccess = onSuccess; } + //A function that add random input based on the editor added gameObject void AddAleatoryInput() { int random = Random.Range(0, _buttons.Length); diff --git a/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayInteractable.cs b/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayInteractable.cs index f28982204edb6c4afc53482f28c8cfeb7b99152d..c083f7686963879da589cca1198f84bb695e9961 100644 --- a/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayInteractable.cs +++ b/UnityGoesBruh/Assets/Scripts/Simon Say/SimonSayInteractable.cs @@ -18,6 +18,7 @@ namespace Assets.Scripts.Simon_Say } + //Interaction of symon say public override GameObject Interact() { _animator.SetTrigger("ButtonPressed");