Guest User

Untitled

a guest
Jan 3rd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. using Mirror;
  2. using UnityEngine;
  3.  
  4. public class PlayerConnectionObject : NetworkBehaviour
  5. {
  6. public GameObject PlayerUnitGameObject;
  7.  
  8. //public GameObject refer;
  9. public GameObject refer;
  10.  
  11. public static PlayerConnectionObject singelton;
  12. // Start is called before the first frame update
  13. private void Start()
  14. {
  15. if (hasAuthority)
  16. {
  17. singelton = gameObject.GetComponent<PlayerConnectionObject>();
  18.  
  19. }
  20. }
  21.  
  22.  
  23. // Update is called once per frame
  24. private void Update()
  25. {
  26. if (Input.GetKeyDown(KeyCode.P))
  27. if (isLocalPlayer)
  28. CmdSpawn();
  29.  
  30. }
  31.  
  32. [Command]
  33. private void CmdSpawn()
  34. {
  35. refer = Instantiate(PlayerUnitGameObject);
  36. refer.transform.Translate(Random.Range(-2f, 2f), Random.Range(0f, 4f), Random.Range(0f, 1f));
  37. NetworkServer.Spawn(refer);
  38. // NetworkServer.Spawn(refer,connectionToClient);
  39. }
  40.  
  41.  
  42. [Command]
  43. public void CmdMove(Vector3 positionTransform)
  44. {
  45. Debug.Log("server doing stuff");
  46. refer.transform.position = positionTransform;
  47. }
  48.  
  49.  
  50. }
Add Comment
Please, Sign In to add comment