Control instantiated object with nav mesh
Options
Hi there,
I'm trying to get a really basic example working where on joined room I instantiate an object such as a cube that has a nav mesh agent component. I would then like each player that joins the room to be able to move their object around and through the use of RPCs sync this movement. Here's the code that I have right now:
Thanks!
I'm trying to get a really basic example working where on joined room I instantiate an object such as a cube that has a nav mesh agent component. I would then like each player that joins the room to be able to move their object around and through the use of RPCs sync this movement. Here's the code that I have right now:
using UnityEngine; using Photon; public class RandomMatchmaker : Photon.PunBehaviour { public GameObject TestPlayer; public UnityEngine.AI.NavMeshAgent BoxNavMesh; public PhotonView ObjectPV; // Use this for initialization void Start() { PhotonNetwork.ConnectUsingSettings("0.1"); } void OnGUI() { GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString()); } public override void OnJoinedLobby() { PhotonNetwork.JoinRandomRoom(); } void OnPhotonRandomJoinFailed() { Debug.Log("Can't join random room!"); PhotonNetwork.CreateRoom(null); } public override void OnJoinedRoom() { Debug.Log("Joined a room!"); GameObject instantiatedObj = PhotonNetwork.Instantiate("Prefabs/TestPlayer", Vector3.zero, Quaternion.identity, 0); TestPlayer = instantiatedObj.gameObject; BoxNavMesh = TestPlayer.GetComponent<UnityEngine.AI.NavMeshAgent>(); } void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 800)) { this.photonView.RPC("UpdatePosition", PhotonTargets.All, hit.point); } } } [PunRPC] void UpdatePosition(Vector3 HitPoint) { BoxNavMesh.destination = HitPoint; } }The issue that I'm having is that even though 2 cubes are instantiated when 2 clients are in the game, both clients control the same object instead of each controlling their own. How can I make it so each player moves their own cube?
Thanks!
0