There is an object (agent.gameObject) with a moving NavMesh Agent on a static floor object.
Navigation has already been baked.
The code below says "WhenMove ()is executed, this object moves up to 20m randomly on the x and z axes".
NavMeshAgent agent;
void Move () {
Vector3 position = new Vector3 (gameObject.transform.position.x + Random.Range (-20, 20), 0.2f, gameObject.transform.position.z + Random.Range (-20, 20));
NavMeshHit Hit;
if (NavMesh.SamplePosition (position, out Hit, 1.0f, NavMesh.AllAreas))
{
destination = position;
}
if (agent.pathStatus! = NavMeshPathStatus.PathInvalid)
agent.SetDestination (destination);
else
Debug.Log ("NaMeshPath none");
}
Now when you runMove (), nothing happens.
I try to runSetDestination ()orDebug.Log ()near the end of the code, but nothing really happens.
Erasing the lastif (~~),else Debug.Log ()and leaving justSetDestination ()
The error"SetDestination" can only be called on an active agent that has been placed on a NavMesh.
occurs.
If i executeMove ()a dozen seconds after the start of debugging, nothing happens.
I'm not sure whyagent.pathStatus! = NavMeshPathStatus.PathInvalidis not true.
OrNavMesh.SamplePosition ()is going to correct the destination,
Is this wrong?
Please answer.
-
Answer # 1
Related articles
- c # - does not fall with velocity (2d)
- c # - taskiscompleted does not become true
- c # readieeeblock does not respond
- c # - compare tag does not respond!
- c # - json value does not match code value
- c # - invoke does not work well
- c # - ontriggerenter2d does not work
- javascript does not start
- apache does not start
- python - pytorch view() does not work
- php - laravel app does not work on docker
- [python] seleniumclick does not work
- android - ios simulator does not start
- css does not hit at all
- visual studio code - vs code does not open from terminal
- javascript - does js (jquery) not work?
- nginx - container does not start
- html - position absolute does not work
- linux - crontab does not work
- html - max-width does not work
- c # - determining if unity collider a fits perfectly in collider b
- c # - variable length cannot be used
- c # - how to manage the number of clicks of multiple objects and stop displaying the number of times
- c # - [unity] in tps 3d games on smartphones, i want to prevent the camera angle from being moved by the finger touching the joy
- c # - if you add public, an error will occur
- c # - collision detection between the stage and the car is not possible
- c # - i want to display at the previous scroll position when reopening in the scroll view of unity
- c # - [unity] even though "has exit time" of animator is specified, it will transition to another state earlier than t
- c # - i want the camera to follow the player character in a tps game, but if i make multiple players in multiplayer, the camera
- c # - missingreferenceexception occurs even though there is a reference
I changed theAgent Typeof the
agent to something that already exists.
Although it is not a fundamental solution, the problem that NavMesh does not work has been solved, so I solved it myself.