Understandable Answer to frequesntly asked question - clarified for noobs like me
I had a valley with a draw bridge that was up and wanted people to be able to cross it only when the bridge was down. So I had a NavMesh path across that area for the bridge and put in on a separate NavMesh Layer. The problem was changing the NavMesh Walkable on objects at runtime to include that layer. i researched and saw answers that made no sense to me . So i just started plugging in numbers to see what happens and finally understand it. The code was simple but figuring out the layer thing was mind boggling. so here is a simplified version of the code and what numbers translate to what masks:
using UnityEngine;
using System.Collections;
public class layerMaskChange : MonoBehaviour {
public GameObject enemy;
NavMeshAgent agent;
public int newWalkable = 97;
void Start () {
agent = enemy.GetComponent<NavMeshAgent>();
}
void OnTriggerEnter(Collider other) {
if(other.tag == "enemy"){
agent.walkableMask = newWalkable;
}
}
}
And how I got 97:
-1 Everything
0 Nothing
1 Default
2 Not Walkable
3 Default and Not Walkable
4 Jump
5 Jump and Default
6 Jump and Not Walkable
7 Jump and Not Walkable and Default
8 Terrain ( my user layer 0)
9 Terrain and default
10 Terrain and N0t Walkable
so you can see where this is going. to finally get to the new layers I wanted:
16 my Layer 1
32 my layer 2
64 my layer 3
and FINALLY what I was searching for : 97 my layer2, my layer3, and Default
Your answer
Follow this Question
Related Questions
NavMesh change from walkable to NOT walkable at runtime 0 Answers
Why does Nav Mesh Run Slower in build mode than in Editor? 1 Answer
Change lightmaps ar runtime 2 Answers
Inspector value changed automatically to an old value on runtime 0 Answers
How to gradually change color of sprite during runtime 0 Answers