0
\$\begingroup\$

I am trying to test out the new Navmesh tools as of Unity 2018.1

So i have a simple scene with a plane:

enter image description here

Then i have the following script:

    public class SpawnObject : MonoBehaviour
{
    public GameObject ObjectToSpawn;
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.name == "floor")
                {
                    Instantiate(ObjectToSpawn, hit.point, Quaternion.identity);
                    NavMeshBuilder.BuildNavMeshAsync();
                }
            }
        }
    }
}

This spawns a prefab and then i attempt to update the navmesh however nothing really happens:

enter image description here

The cube I am spawning has the following properties:

enter image description here

Can anyone tell me what I am doing wrong?

\$\endgroup\$
1
\$\begingroup\$

It looks like your object is not marked as nav mesh static and is not a nav mesh obstacle.

Either change the static flags on the prefab (press the down arrow next to the “static” checkbox) or add a nav mesh obstacle component.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.