private void Awake() { if (instance == null) { instance = this; PrepareRocket(); } else { Destroy(gameObject); } }
//Create bots public bool Init(string[] teamNames, RoundMaster round) { this.master = round; // create rockets this.rockets = new RocketPool(); this.rockets.InitPool(this.rocketSettings.RockePoolNumber, this.rocketSettings.RocketPrefab); // create teams this.teams = new Team[teamNames.Length]; for (int i = 0; i < this.teams.Length; i++) { GameObject team_root = Instantiate(this.gameSettings.Teamprefab, Vector3.zero, Quaternion.identity); team_root.name = "TEAM_" + teamNames[i]; this.teams[i] = team_root.GetComponent <Team>(); this.teams[i].team_color = team_color[i]; this.teams[i].layer = LayerMask.NameToLayer(layers[i]); } for (int i = 0; i < this.teams.Length; i++) { this.teams[i].Init(this, i); this.teams[i].SetPositions(this.teamPlaces[i]); } // create bots bots = new Bot[this.teamSettings.BotNumber * 2]; for (int i = 0; i < this.teams.Length; i++) { teams[i].bots = new Bot[this.teamSettings.BotNumber]; for (int j = 0; j < this.teamSettings.BotNumber; j++) { GameObject bot_go = (GameObject)GameObject.Instantiate(this.gameSettings.BotPrefab, this.teams[i].Places.GetPlacePosition(KeyPlaces.SPAWN), Quaternion.identity); bot_go.GetComponent <Renderer>().material.color = team_color[i]; bot_go.layer = teams[i].layer; bot_go.transform.parent = this.teams[i].transform; bot_go.name = "bot-" + j + "_team-" + i; Bot bot_infos = bot_go.GetComponent <Bot>(); bot_infos.Init(j * HASH_MULTIPLICATOR + i, this); teams[i].bots[j] = bot_infos; bots[i * this.teamSettings.BotNumber + j] = bot_infos; } } // register behaviour for (int i = 0; i < this.teams.Length; i++) { // team behaviour string team_script = FindScriptContainingWords(teamNames[i], "team"); if (team_script == "") { return(false); } this.teams[i].gameObject.AddComponent(System.Type.GetType(team_script)); var teamBehaviour = this.teams[i].GetComponent <TeamBehaviour>(); this.teams[i].RegisterBehaviour(teamBehaviour.Init, teamBehaviour); // bots behaviour string bot_script = FindScriptContainingWords(teamNames[i], "bot"); if (bot_script == "") { return(false); } for (int j = 0; j < this.teams[i].bots.Length; j++) { this.teams[i].bots[j].gameObject.AddComponent(System.Type.GetType(bot_script)); BotBehaviour behaviour = this.teams[i].bots[j].GetComponent <BotBehaviour>(); this.teams[i].bots[j].RegisterBehaviour(behaviour.Init, behaviour); } teamBehaviour.RegisterBot(this.teams[i].bots); } // create flags this.flags = new Flag[2]; for (int i = 0; i < this.teams.Length; i++) { var index = i; GameObject flagGo = Instantiate(this.gameSettings.FlagPrefab) as GameObject; flags[i] = flagGo.GetComponent <Flag>(); flags[i].name = "flag_" + i; flags[i].tag = "Flag"; flags[i].GetComponent <Renderer>().material.color = team_color[i]; this.teams[index].SetFlag(flags[index]); flags[i].Init(this, this.teams[i]); flags[i].Disable(); } respawnList = new List <RespawnData>(); return(true); }