Hi gang, I have Instantiated a navmesh Agent on a cube, both the Spawnpoint and the Baked Navmesh plane are at 0,0,0 so it should be spawning on the Navmeshplane but I’m getting the
Notp laced on navmesh Error any way to fix this?
“GetRemainingDistance” can only be called on an active agent that has been placed on a NavMesh.
Everything is setup correctly.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using Photon;
public class PlayerMove : Photon.MonoBehaviour {
public float ShootDistance = 10;
public PlayerShooting PlayerShoot;
public NavMeshAgent Agent;
private Ray ShootingRay;
private RaycastHit shootHit;
public bool TeamOne;
public bool TeamTwo;
private bool enemyClicked;
// Use this for initialization
void Start () {
if (photonView.isMine == true) {
gameObject.tag = "MyPlayer";
Agent = gameObject.GetComponent<NavMeshAgent> ();
Agent.GetComponent<NavMeshAgent> ();
}
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Input.GetButtonDown ("Fire2")) {
if (Physics.Raycast (ray, out hit, 10000)) {
if (TeamOne == true) {
if (hit.collider.CompareTag ("TeamTwo")) {
enemyClicked = true;
Agent.Resume ();
}
}
if (TeamTwo == true) {
if (hit.collider.CompareTag ("TeamOne")) {
enemyClicked = true;
}
}
} else {
enemyClicked = false;
Agent.destination = hit.point;
Agent.Resume ();
}
}
if (Agent.remainingDistance <= Agent.stoppingDistance) {
Agent.Stop ();
} else {
Agent.Resume ();
}
if (enemyClicked == true && Agent.remainingDistance < ShootDistance) {
PlayerShoot.Shooting = true;
} else {
PlayerShoot.Shooting = false;
}
}
}