- Home /
Question by
WeirderChimp · Jul 27, 2014 at 08:31 AM ·
spawnspawnpointsfindobjectsoftype
FindObjectOfType with Variable
hey
ive been trying to figure out how to spawn my player in a multiplayer game only on my teams spawns
my code is:
public void SpawnMyPlayer ()
{
SpawnBeds = GameObject.FindObjectsOfType<Vessel_SpawnBed>().Equals(;
SpawnIslands = GameObject.FindObjectsOfType<Map_IslandSpawn>();
Transform MySpawn;//the position where i will spawn
//AddChatMessages("Spawning: " + PhotonNetwork.player.name);
if (SpawnBeds != null)
{
MySpawn = SpawnBeds[ Random.Range (0, SpawnBeds.Length) ];
}else{
MySpawn = SpawnIslands[ Random.Range (0, SpawnBeds.Length) ];
}
MyPlayerInfo.MyPlayer = (GameObject)PhotonNetwork.Instantiate("Player", MySpawn.transform.position, MySpawnBed.transform.rotation, 0);
MyPlayerInfo.MyPlayer.tag = "MyPlayer";
MenuCamera.SetActive(false);
}
where the line is that i find My SpawnBeds that gives me an array of all the spawn beds in the scene but i only want the spawn beds with the TeamId variable of 0
How do i do this its been stumping me for a while
thanks ~Scott
Comment
Answer by dsada · Jul 27, 2014 at 08:57 AM
My idea:
List<Vessel_SpawnBed> SpawnBeds = new List<Vessel_SpawnBed>();
SpawnBeds = GameObject.FindObjectsOfType<Vessel_SpawnBed>().ToList();
SpawnBeds = SpawnBeds.FindAll(spawn => spawn.TeamdId == 0);
make sure you are
using Linq;
and make available your TeamId variable by making it public or something