private void SpawnPlayer(NetworkPlayer netPlayer, int index) { GameObject startSpots = GameObject.Find("Start Spots"); startSpots spotList = startSpots.GetComponent <startSpots>(); if (netPlayer == Network.player) { Debug.Log("spawned player: " + index); Transform start = spotList.startPositions[index].transform; GameObject racer = (GameObject)Network.Instantiate(playerRacer, start.position, start.rotation, 0); racer.AddComponent <PlayerController>(); racer.GetComponent <playerRacer>().SetStartPoint(start.position, start.rotation); racer.GetComponent <RacerInformation>().SetName(nameList[index]); racingManager.AddRacer(racer, index); } }
private void SpawnAI(int index) { // only let server execute function // need both isServer checks to prevent dupe spawns if (Network.isServer) { GameObject startSpots = GameObject.Find("Start Spots"); startSpots spotList = startSpots.GetComponent <startSpots>(); Debug.Log("spawned ai: " + index); Transform start = spotList.startPositions[index].transform; GameObject racer = (GameObject)Network.Instantiate(playerRacer, start.position, start.rotation, 0); racer.AddComponent <AIController>(); racer.GetComponent <playerRacer>().SetStartPoint(start.position, start.rotation); racer.GetComponent <RacerInformation>().SetName(aiNames[Random.Range(0, aiNames.Length)]); racingManager.AddRacer(racer, index); } }