Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

NavMesh.GetAreaFromName

Switch to Manual
public static function GetAreaFromName(areaName: string): int;

Parameters

areaName Name of the area to look up.

Returns

int Index if the specified are, or -1 if no area found.

Description

Returns the area index for a named NavMesh area type.

#pragma strict
// NearestPointOnWater.cs
public class NearestPointOnWater extends MonoBehaviour {
	function Update() {
		// Find nearest point on water.
		var waterMask: int = 1 << NavMesh.GetAreaFromName("water");
		var hit: NavMeshHit;
		if (NavMesh.SamplePosition(transform.position, 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.