| areaName | Name of the area to look up. |
int Index if the specified are, or -1 if no area found.
Returns the area index for a named NavMesh area type.
#pragma strict
// NearestPointOnWater.cs
public class NearestPointOnWater {
function Update() {
// Find nearest point on water.
var waterMask = 1 << NavMesh.GetAreaFromName("water");
var hit;
if (NavMesh.SamplePosition(transform.position, hit, 2.0f, waterMask)) {
Debug.DrawRay(hit.position, Vector3.up, Color.blue);
}
}
}
// NearestPointOnWater.cs using UnityEngine; using System.Collections; public class NearestPointOnWater : MonoBehaviour { void Update() { // Find 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); } } }
See also:
• Areas and Costs – to learn how to use different Area types.