public void SwitchCurrentLevel() { if (PreviousLevel == null) { PreviousLevel = CurrentLevel; } else { PreviousLevel.SetActive(false); CurrentLevel = NextLevel; } LevelBehaviour levelBehaviour = CurrentLevel.GetComponent <LevelBehaviour>(); GameObject nextLevel = levelBehaviour.GetPossibleNextLevel(); LevelBehaviour nextLevelBehaviour = CurrentLevel.GetComponent <LevelBehaviour>(); Vector3 nextLevelPosition = levelBehaviour.GetNextLevelPosition(nextLevelBehaviour); NextLevel = Instantiate(nextLevel); NextLevel.transform.position = nextLevelPosition; //////////////////////////////// USING SINGLETON /////////////////////////////////////// ScoreBehaviour.Instance.UpdateScore(); //////////////////////////////// USING SINGLETON /////////////////////////////////////// }
public void PlayerDied() { var deadPlayer = DeadPlayersModular.Items[DeadPlayersModular.Items.Count - 1]; if (ActivePlayersModular.Items.Count == 0) { Debug.LogError("Everyone's dead!"); return; } // Is there only one team? bool oneTeamRemaining = true; var winningTeamValue = ActivePlayersModular.Items[0].Settings.Team; for (int i = 1; i < ActivePlayersModular.Items.Count; i++) { if (winningTeamValue != ActivePlayersModular.Items[i].Settings.Team) { oneTeamRemaining = false; break; } } // If more than one team, battle is still on if (!oneTeamRemaining) { return; } WinningTeam = Teams[winningTeamValue]; // If the attacker team won, we're moving forward in the sequence bool forwardInSequence = WinningTeam.Role == Role.Attacker; NextLevelIndex = CurrentLevelIndex + (forwardInSequence ? +1 : -1); // If there's a level to go, we get it if (NextLevelIndex >= 0 && NextLevelIndex < LevelSequence.Length) { Level nextLevel = NextLevel; // Open level gates var currentLevelGate = CurrentLevel.Gates[WinningTeam.Side.GetOpposite()]; var nextLevelGate = nextLevel.Gates[WinningTeam.Side]; currentLevelGate.OpenForLeaving(); nextLevelGate.OpenForEntering(); // position next level on the appropriate side // @TODO USE BOUNDS, NOT SIZE // @TODO USE BOUNDS, NOT SIZE // @TODO USE BOUNDS, NOT SIZE var currentLevelBounds = CurrentLevel.GetComponent <BoxCollider>(); var nextLevelBounds = nextLevel.GetComponent <BoxCollider>(); Vector3 nextLevelside = WinningTeam.Side.GetOpposite().GetVector(); nextLevel.transform.position = CurrentLevel.transform.position + nextLevelside * .5f * (currentLevelBounds.size.x * currentLevelBounds.transform.lossyScale.x + nextLevelBounds.size.x * nextLevelBounds.transform.lossyScale.x); // Procceed GameGUI.Instance.Go(WinningTeam.Side.GetOpposite()); nextLevel.gameObject.SetActive(true); } else { GameGUI.Instance.Winner(WinningTeam.Color); Debug.Log(WinningTeam.name + " Won!"); } }
public IEnumerator SetAutoAttack() { if (AutoAttackEnabled || Attacks.Count == 0 || AutoAttacksActivated > 0) { yield break; } AutoAttacksActivated++; AutoAttackEnabled = true; while (DistanceFrom(Player.transform.position) <= RequiredDistanceFromPlayer && HP > 0 && AutoAttackEnabled) { while (Paused) { yield return(null); } yield return(new WaitForSeconds(AttackInterval)); if (HP <= 0 || !AutoAttackEnabled) { break; } if (HasAttackAnimation) { GetComponent <Animator>().Play("Attack"); } switch (Attacks[Random.Range(0, Attacks.Count)]) { case TypeOfAttack.Course: Instantiate(CoursePrefab, transform.position, Quaternion.identity); break; case TypeOfAttack.Shooting: Instantiate(Bullet, transform.position, new Quaternion(0, FaceRight ? 0 : 180, 0, 0)).GetComponent <Shell>().FaceRight = FaceRight; break; case TypeOfAttack.Static: int x = Player.GetComponent <Player>().X, tY = Player.GetComponent <Player>().Y; while (tY > 0) { Debug.Log("tY = " + tY.ToString() + ", x = " + x.ToString()); if (CurrentLevel.GetComponent <Level>().CellBlock[tY, x] == BlockType.None && CurrentLevel.GetComponent <Level>().CellBlock[tY - 1, x] != BlockType.None) { break; } tY--; } Instantiate(StaticAttackPrefab, new Vector3(Player.GetComponent <Player>().X * 0.32F, (tY < 0 ? 0 : tY) * 0.32F + 0.16F, 0), Quaternion.identity); break; case TypeOfAttack.Obstruction: Instantiate(ObstructionPrefab, new Vector3(Player.GetComponent <Player>().X * 0.32F, (Player.GetComponent <Player>().Y + 2) * 0.32F, 0), Quaternion.identity); break; default: break; } } AutoAttacksActivated--; yield break; }