GetAreaFromName(string)
Returns the area index for a named NavMesh area type.
Read time 1 minuteLast updated 8 days ago
Definition
- Type: Method
- Namespace: UnityEngine.AI
- Assembly: UnityEngine.AIModule
public static int GetAreaFromName(string areaName)
Parameters
Name of the area to look up.
Returns
Type | Description |
|---|---|
| int | Index if the specified area name exists, or -1 if no area type has the specified name. |
Remarks
// NearestPointOnWaterusing UnityEngine;using UnityEngine.AI;public class NearestPointOnWater : MonoBehaviour{ void Update() { // Find the nearest point on water. int waterMask = 1 << NavMesh.GetAreaFromName("water"); NavMeshHit hit; if (NavMesh.SamplePosition(transform.position, out hit, 2.0f, waterMask)) { Debug.DrawRay(hit.position, Vector3.up, Color.blue); } }}
Additional Resources: Areas and Costs to learn how to use different Area types.