Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Mirror;
- using UnityEngine;
- public class PlayerConnectionObject : NetworkBehaviour
- {
- public GameObject PlayerUnitGameObject;
- //public GameObject refer;
- public GameObject refer;
- public static PlayerConnectionObject singelton;
- // Start is called before the first frame update
- private void Start()
- {
- if (hasAuthority)
- {
- singelton = gameObject.GetComponent<PlayerConnectionObject>();
- }
- }
- // Update is called once per frame
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.P))
- if (isLocalPlayer)
- CmdSpawn();
- }
- [Command]
- private void CmdSpawn()
- {
- refer = Instantiate(PlayerUnitGameObject);
- refer.transform.Translate(Random.Range(-2f, 2f), Random.Range(0f, 4f), Random.Range(0f, 1f));
- NetworkServer.Spawn(refer);
- // NetworkServer.Spawn(refer,connectionToClient);
- }
- [Command]
- public void CmdMove(Vector3 positionTransform)
- {
- Debug.Log("server doing stuff");
- refer.transform.position = positionTransform;
- }
- }
Add Comment
Please, Sign In to add comment