agent removed

This commit is contained in:
Steven 2017-09-27 23:56:52 -05:00
parent ef859cbd0d
commit 2bcee7add8

View file

@ -4,7 +4,6 @@ using UnityEngine.AI;
public class SimpleNPCBehavior : Photon.PunBehaviour public class SimpleNPCBehavior : Photon.PunBehaviour
{ {
private NavMeshAgent agent;
private bool setTarget = true; private bool setTarget = true;
enum State { enum State {
@ -15,7 +14,6 @@ public class SimpleNPCBehavior : Photon.PunBehaviour
void Start() void Start()
{ {
agent = GetComponent<NavMeshAgent>();
//agent = gameObject.AddComponent<NavMeshAgent>(); //agent = gameObject.AddComponent<NavMeshAgent>();
if (PhotonNetwork.isMasterClient) { if (PhotonNetwork.isMasterClient) {
photonView.RPC("TeleportToTarget", PhotonTargets.All, GetRandomLocation()); photonView.RPC("TeleportToTarget", PhotonTargets.All, GetRandomLocation());
@ -36,6 +34,11 @@ public class SimpleNPCBehavior : Photon.PunBehaviour
} }
} }
NavMeshAgent GetAgent()
{
return GetComponent<NavMeshAgent>();
}
IEnumerator UpdateDestination() IEnumerator UpdateDestination()
{ {
yield return new WaitForSeconds(Random.Range(0.1f, 10.0f)); yield return new WaitForSeconds(Random.Range(0.1f, 10.0f));
@ -59,14 +62,14 @@ public class SimpleNPCBehavior : Photon.PunBehaviour
[PunRPC] [PunRPC]
void SetTarget(Vector3 target) void SetTarget(Vector3 target)
{ {
agent.destination = target; GetAgent().destination = target;
} }
[PunRPC] [PunRPC]
void TeleportToTarget(Vector3 target) void TeleportToTarget(Vector3 target)
{ {
agent.Warp(target); GetAgent().Warp(target);
agent.destination = target; GetAgent().destination = target;
} }
[PunRPC] [PunRPC]