public void StartBattle(GameObject enemyGameObject) { // Once collided with enemy, starta fight. // I will need enemy information coming through here enemyToFight = enemyGameObject.GetComponent <EnemyBehavior>().prefab; enemyLevel = enemyGameObject.GetComponent <EnemyBehavior> ().level; enemyTeam = enemyGameObject.GetComponent <EnemyBehavior> ().team; // Get the colour of the tile the enemy was on for the battle groundTileResources = GameObject.Find("Map").GetComponent <Map> ().getTileFromPos(enemyGameObject.transform.position).GetComponent <MapGridUnit>().resources; playerMapPosition = worldPlayer.GetComponent <Transform>(); //print (playerMapPosition.position.ToString ()); //GameObject.Destroy (worldPlayer); // Disable the World version of player worldPlayer.SetActive(false); // disable the bases for each team on the world map for (int i = 0; i < teams.Count; i++) { teams [i].SetActive(false); } combatants = new List <CharacterClass> (); CharacterClass tempCharacterClass; for (int i = 0; i < playerCharacters.Count; i++) { tempCharacterClass = playerCharacters [i]; combatants.Add(tempCharacterClass); } // for now 2 enemies of collided type for (int i = 0; i < 2; i++) { tempCharacterClass = new CharacterClass(); tempCharacterClass.Initialize("Enemy " + i.ToString(), enemyLevel, 1, enemyTeam); combatants.Add(tempCharacterClass); } LoadScene("Battle"); inBattle = true; }
void Awake() { // Makes sure that the GameManager this is attached to is always the same one, so we can use it to keep values through scenes. if (instance == null) { instance = this; Scene currentScene = SceneManager.GetActiveScene(); string sceneName = currentScene.name; if (sceneName == "Battle") { inBattle = true; } else { inBattle = false; } worldPlayer = GameObject.Instantiate(playerWorldSprite, new Vector3(90, 2, 0), Quaternion.identity); worldPlayer.transform.SetParent(gameObject.transform); playerMapPosition = worldPlayer.transform; //playerMapPosition = new Vector3(0,3,0); //playerMapPosition = GameObject.Find("Player").GetComponent<Transform>().position; /****************************************** Start of the game here ***********************************************************/ // This will be called once at the very start of the game and then never again, good place to set up one time events at the start. // Create Main character, probably will be more involved than this later :P playerCharacters = new List <CharacterClass> (); teams = new List <GameObject> (); // Add Main CharacterPlayer character CharacterClass temp = new CharacterClass(); // Initialize stats to level 40 so we can beat level 15 generated badguy easily temp.Initialize("Main Character", 40, 0, "Player"); playerCharacters.Add(temp); currentPlayerCharacters += 1; // Add second player character CharacterClass temp2 = new CharacterClass(); temp2.Initialize("Secondary Character", 25, 0, "Player"); playerCharacters.Add(temp2); currentPlayerCharacters += 1; // Create the two teams and set their parent transforms to this gameobject (to not be destroyed) GameObject tempTeam1 = GameObject.Instantiate(Resources.Load("Blue Base"), new Vector3(0, 1, 0), Quaternion.identity) as GameObject; tempTeam1.GetComponent <Transform> ().parent = gameObject.transform; teams.Add(tempTeam1); GameObject tempTeam2 = GameObject.Instantiate(Resources.Load("Red Base"), new Vector3(90, 1, 90), Quaternion.identity) as GameObject; tempTeam2.GetComponent <Transform> ().parent = gameObject.transform; teams.Add(tempTeam2); //teams[0].GetComponent<Team>().Initialize(); //teams[1].GetComponent<Team>().Initialize(); // Initialize everything that would also be initialized post battle // Apply the movement controls for the world map to the player WorldMovementControls WMC = worldPlayer.AddComponent <WorldMovementControls> (); WMC.moveSpeed = 20; WMC.RotationSpeed = 1; if (sceneName == "Hoil") { InitializeWorld(); } else if (sceneName == "Battle") { print("Started in Battle"); StartBattle(); } } else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(gameObject); }