Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine.Networking;
  4. using UnityEngine;
  5.  
  6. public class PlayerManager : NetworkBehaviour {
  7.  
  8. GameObject Panel;
  9.  
  10. public GameObject PlayerUnitPrefab;
  11.  
  12. // Update is called once per frame
  13. void Update () {
  14. if (!isLocalPlayer)
  15. return;
  16.  
  17. if (Input.GetKeyDown(KeyCode.Space)) {
  18. CmdSpawnPlayer(gameObject);
  19. }
  20. }
  21.  
  22. [Command]
  23. void CmdSpawnPlayer(GameObject hospitalizedPlayer) {
  24. hospitalizedPlayer = Instantiate(PlayerUnitPrefab);
  25. NetworkServer.Spawn(hospitalizedPlayer);
  26.  
  27. RpcSpawnPlayer(hospitalizedPlayer);
  28. }
  29.  
  30. [ClientRpc]
  31. void RpcSpawnPlayer(GameObject player) {
  32. Panel = GameObject.Find("Panel");
  33. player.transform.SetParent(Panel.transform);
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement