public bool SummonPlayer(int which, Vector2 position) { if (!PabloTools.TryForNullDebugError(prefabPlayer, "There's no prefab for the player " + which.ToString())) { return(false); } // Instantiate players[which] = Instantiate(prefabPlayer, position, Quaternion.identity, transform) as GameObject; if (!PabloTools.TryForNullDebugError(players[which], "Cannot instantiate player " + which.ToString())) { return(false); } // Get player script playersScript[which] = players[which].GetComponent <EntityPlayer>(); if (playersScript[which] == null) { Debug.LogError("Cannot find player script in player " + which); return(false); } // And now set it playersScript[which].Set(which); return(true); }
private IEnumerator ActionRecoveryPerform() { PabloTools.TryForNullSetActive(preparationRecovery, true); yield return(new WaitForSeconds(preparationRecoveryDelay)); ActionRecoveryEnd(); }
// Recovery private void ActionRecoveryBegin() { isDefending = false; PabloTools.TryForNullSetActive(preparationDefense, false); PabloTools.TryForNullSetActive(preparationAttack, false); //Debug.Log( " x Action recovery " ); currentAction = StartCoroutine(ActionRecoveryPerform()); }
// Defense private IEnumerator ActionDefense() { canMove = false; isDefending = true; PabloTools.TryForNullSetActive(preparationDefense, true); yield return(new WaitForSeconds(preparationDefenseDelay)); ActionRecoveryBegin(); }
// Attack private IEnumerator ActionAttack() { isPreparingAttack = false; canMove = false; PabloTools.TryForNullSetActive(preparationInit, false); PabloTools.TryForNullSetActive(preparationAttack, true); yield return(new WaitForSeconds(preparationAttackDelay)); ActionRecoveryBegin(); }
private void ActionRecoveryEnd() { // Finish PabloTools.TryForNullSetActive(preparationRecovery, false); canMove = true; }
// Attack preparation private void ActionAttackPreparation() { // Prepare the attack PabloTools.TryForNullSetActive(preparationInit, true); isPreparingAttack = true; }
private void ChangeScene(Structs.GameScene to) { currentScene = to; //Debug.Log("Change scene to: " + currentScene); switch (currentScene) { case Structs.GameScene.Initialization: SwitchToMenu(); break; case Structs.GameScene.Menu: managerUI.SetPanels(); //managerInput.SetEvents(); // using rewired managerCamera.UpdateCameras(); // This will be called from the update with input //GameBegin(); // Reset game. Only set score to 0 for now managerGame.Initialize(); break; case Structs.GameScene.LoadingGame: managerUI.SetPanels(); SwitchToIngame(); break; case Structs.GameScene.Ingame: // This loads the map, sets the player and the camera // Using the number of the level //LoadLevel(); // Load the 2 players bool playerSummoningFailed = managerEntity.SummonPlayers(); if (!playerSummoningFailed) { Debug.LogError("Failed instantiating players "); GameEnd(); return; } // And subscribe to endgame conditions if (managerEntity.playersScript[0] != null) { PabloTools.Bind(ref managerEntity.playersScript[0].OnDie, GameReset); } if (managerEntity.playersScript[1] != null) { PabloTools.Bind(ref managerEntity.playersScript[1].OnDie, GameReset); } // Set managers //managerInput.SetEvents(); // using rewired managerUI.SetPanels(); managerCamera.UpdateCameras(); // Play start sfx managerAudio.PlaySfx(ManagerAudio.Sfx.Start); break; case Structs.GameScene.GameReset: // Update score if (managerEntity.playersScript[0].state == EntityPlayer.PlayerState.Alive) { Director.Instance.managerGame.ScoreIncrease(0); } else if (managerEntity.playersScript[1].state == EntityPlayer.PlayerState.Alive) { Director.Instance.managerGame.ScoreIncrease(1); } // Unsubscribe from endgame conditions and remove players if (managerEntity.playersScript[0] != null) { PabloTools.Unbind(ref managerEntity.playersScript[0].OnDie); } if (managerEntity.playersScript[1] != null) { PabloTools.Unbind(ref managerEntity.playersScript[1].OnDie); } managerEntity.Reset(); //managerMap.Reset(); GameBegin(); break; case Structs.GameScene.GameEnd: // Unsubscribe from endgame conditions and remove players if (managerEntity.playersScript[0] != null) { PabloTools.Unbind(ref managerEntity.playersScript[0].OnDie); } if (managerEntity.playersScript[1] != null) { PabloTools.Unbind(ref managerEntity.playersScript[1].OnDie); } managerEntity.Reset(); //managerMap.Reset(); //managerInput.SetEvents(); // using rewired managerUI.SetPanels(); SwitchToMenu(); break; case Structs.GameScene.Exit: Application.Quit(); break; } }