/// <summary> /// Initializes the characters /// </summary> /// <param name="index">Index of character which should be initialized</param> private void InitCharacters(int index) { if (index == 0) { _characterList = new List <GameObject>(Datasheet.Heroes()); } else { _characterList = new List <GameObject>(Datasheet.Mobs()); } _totalCharacters = _characterList.Count; Debug.Log("[CharacterSelection.cs]: Number of heroes: " + _characterList.Count); _basicScales = new List <Vector3>(_totalCharacters); for (int i = 0; i < _totalCharacters; i++) { _basicScales.Add(new Vector3()); } _currentCharacter = 0; float arc = 2 * Mathf.PI / _totalCharacters; float currentArc = 0; _positions = new List <Vector3>(_totalCharacters); for (int i = 0; i < _totalCharacters; i++) { _positions.Add(new Vector3((-80) * Mathf.Sin(currentArc), 0, (-80) * Mathf.Cos(currentArc))); currentArc += arc; } for (int i = 0; i < _totalCharacters; i++) { _characterList[i] = (GameObject)Instantiate(_characterList[i]); _characterList[i].GetComponent <Character>().Type = Character.Types.CHARACTER_SELECTION; if (index == 0) { _basicScales[i] = _characterList[i].transform.localScale / 1.6f; _characterList[i].transform.position = _positions[i] + (new Vector3(0, 0, 0) * _basicScales[i].y); } else { _basicScales[i] = _characterList[i].transform.localScale / 1.6f; _characterList[i].transform.position = _positions[i] + (new Vector3(0, 0, 0) * _basicScales[i].y); } SetScaleToBackground(i); } SetScaleToForeground(_currentCharacter); }
/// <summary> /// Sets the selected Character in GameManager and Loads the nextScene /// </summary> private void SetCharacter() { Character chosenCharacter; if (_toolbarSelectionNew == 0) { chosenCharacter = Datasheet.Heroes()[_currentCharacter].GetComponent <Hero>(); chosenCharacter.DisplayName = _characterList[_currentCharacter].GetComponent <Hero>().DisplayName; chosenCharacter.Type = Character.Types.HUMAN; Debug.Log("Chosen character: " + chosenCharacter.Type); Hero animator = _characterList[_currentCharacter].GetComponent <Hero>(); if (animator.animation != null) { List <string> specialAttackNames = animator.SpecialAttacks(); if (specialAttackNames.Count > 0) { string animationName = specialAttackNames[Random.Range(0, specialAttackNames.Count)]; animator.animation.Play(animationName); StartCoroutine(Wait(animator.animation[animationName].length / animator.animation[animationName].speed, chosenCharacter)); return; } } } else { chosenCharacter = Datasheet.Mobs()[_currentCharacter].GetComponent <Mob>(); chosenCharacter.Type = Character.Types.HUMAN; Mob animator = _characterList[_currentCharacter].GetComponent <Mob>(); if (animator.animation != null) { animator.animation.Play("Attacking"); StartCoroutine(Wait(animator.animation["Attacking"].length / animator.animation["Attacking"].speed, chosenCharacter)); return; } } // If we reach this, then there wasn't an animation to play. Bummer. // Continue and add this character without playing an animation. AddCharacter(chosenCharacter); }
private IEnumerator SpawnMobs() { const int MAXMOBS = 10; List <Checkpoint> checkpoints = (List <Checkpoint>)GameManager.GetInstance().Checkpoints; while (true) { int wronglyCountedEliteMobs = 0; foreach (Mob mob in GameManager.GetInstance().GetTeam(2).GetMobTeamMembers()) { if (mob is EliteMob) { ++wronglyCountedEliteMobs; } } float checkpointCounter = checkpoints.Count / 2; foreach (Checkpoint checkpoint in checkpoints) { if (checkpoint.CheckType(this, Checkpoint.Type.FRIENDLY)) { checkpointCounter -= 0.5f; } else if (checkpoint.CheckType(this, Checkpoint.Type.HOSTILE)) { checkpointCounter += 0.5f; } } int meleeMobs = Mathf.RoundToInt(checkpointCounter * 2 / 3); for (int i = 0; i < meleeMobs; i++) { if (Team.TeamNo == 1) { if (GameManager.GetInstance().GetTeam(1).GetMercenaryTeamMembers().Count >= MAXMOBS) { break; } } else { if (GameManager.GetInstance().GetTeam(2).GetMobTeamMembers().Count >= MAXMOBS + wronglyCountedEliteMobs) { // +2 because someone didn't noticed the elitemobs are mobs break; } } GameObject mob = Team.TeamNo == 1 ? Datasheet.Mercenaries()[1] : Datasheet.Mobs()[0]; this.Spawn(mob); } int rangedMobs = Mathf.RoundToInt(checkpointCounter * 1 / 3); for (int i = 0; i < rangedMobs; i++) { if (Team.TeamNo == 1) { if (GameManager.GetInstance().GetTeam(1).GetMercenaryTeamMembers().Count >= MAXMOBS) { break; } } else { if (GameManager.GetInstance().GetTeam(2).GetMobTeamMembers().Count >= MAXMOBS + wronglyCountedEliteMobs) { // +2 because someone didn't noticed the elitemobs are mobs break; } } GameObject mob = Team.TeamNo == 1 ? Datasheet.Mercenaries()[0] : Datasheet.Mobs()[1]; this.Spawn(mob); } yield return(new WaitForSeconds(SPAWNRATE)); } }