mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-30 13:07:10 +01:00
Switching Teams with btns
This commit is contained in:
@@ -18,7 +18,7 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
[SyncVar(hook = "ChangeReadyState")]
|
||||
[SerializeField] bool ready = false;
|
||||
|
||||
[SyncVar]
|
||||
[SyncVar(hook = "ChangeDisplayTeam")]
|
||||
[SerializeField] int teamId = 0;
|
||||
|
||||
Lobby lobby;
|
||||
@@ -26,14 +26,6 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
{
|
||||
lobby = GameObject.Find("LobbyManager").GetComponent<Lobby>();
|
||||
lobby.RegisterPlayer(this);
|
||||
|
||||
if(teamId == 0)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team1").transform;
|
||||
}else if(teamId == 1)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team2").transform;
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
@@ -45,6 +37,10 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
rdyBtn.onClick.AddListener(CmdChangeReady);
|
||||
CmdSendName(vs.username);
|
||||
lobby.SetTitle(this, "Game Of\n" + username);
|
||||
team1Btn = GameObject.Find("Team1Btn").GetComponent<Button>();
|
||||
team2Btn = GameObject.Find("Team2Btn").GetComponent<Button>();
|
||||
team1Btn.onClick.AddListener(delegate { SelectTeam(1); });
|
||||
team2Btn.onClick.AddListener(delegate { SelectTeam(2); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,4 +79,15 @@ public class LobbyPlayer : NetworkBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ChangeDisplayTeam(int oldTeamId, int newTeamId)
|
||||
{
|
||||
if(newTeamId == 1)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team1List").transform;
|
||||
}else if(newTeamId == 2)
|
||||
{
|
||||
gameObject.transform.parent = GameObject.FindGameObjectWithTag("Team2List").transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user