Hi All,
I’m on lecture 11 of the Multiplayer Basics course “Moving our Player”, and I am now facing the problem of assign the NavMeshagent.
In the video, Nathan serialized the navmesh agent in the code and assign the navmesh agent to it at the inspector.
Instead of assigning the navmesh agent in the inspector, I tried to did it at OnStartAuthority.
Here is my code.
NavMeshAgent agent;
private Camera mainCamera;
#region Server
[Command]
private void CmdMove(Vector3 position)
{
if(!NavMesh.SamplePosition(position, out NavMeshHit hit,1f,NavMesh.AllAreas)) {return;}
agent.SetDestination(hit.position);
}
#endregion
private void HandleTransformColorUpdated(Vector3 oldPos, Vector3 newPos)
{
this.transform.position= newPos;
}
#region Client
public override void OnStartAuthority()
{
agent=GetComponent<NavMeshAgent>();
Debug.Log(agent.isActiveAndEnabled);
Debug.Log(gameObject.name);
base.OnStartAuthority();
mainCamera=Camera.main;
The NavMesh Agent still works for the host’s player.
However, it failed on the player of the client.
Once I try to move the second player, Unity will just shut down the client automatically.
Has anyone faced the same issues?
Thanks.