Good day!
Need help pliss, I am doing a game with navmesh navigation, i want send navMeshAgent.destination to server and in the server to all player, for “prefect syncro”, but not work good, the players move only in server.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class ClassPlayerMovement : NetworkBehaviour
{
public GameObject prefabBullet;
public Transform bulletTransform;
[SyncVar]
NavMeshAgent navMeshAgent;
void Awake()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if(isLocalPlayer)
{
if(Input.GetMouseButton(1))
{
RaycastHit tempHit;
Ray tempRay = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(tempRay, out tempHit, 100, LayerMask.GetMask("layerPlatform")))
{
CmdScrClickAndMove(tempHit.point);
}
}
if(Input.GetKeyDown(KeyCode.Q))
{
RaycastHit tempHit;
Ray tempRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Physics.Raycast(tempRay, out tempHit, 100, LayerMask.GetMask("layerPlatform"));
CmdScrPowerQActive(new Vector3(tempHit.point.x, bulletTransform.position.y, tempHit.point.z));
}
}
}
[Command]
void CmdScrClickAndMove(Vector3 destination)
{
navMeshAgent.SetDestination(destination);
}
[Command]
void CmdScrPowerQActive(Vector3 direction)
{
var tempBullet = (GameObject) Instantiate(prefabBullet, bulletTransform.position, Quaternion.identity);
tempBullet.transform.LookAt(direction);
tempBullet.GetComponent<Rigidbody>().velocity = tempBullet.transform.forward*8;
Destroy(tempBullet, 0.45f);
NetworkServer.Spawn(tempBullet);
}
}
The players are network identity, an local player autority.
How solve this problem?
Thanks uniters!