Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

NavMesh.GetAreaFromName

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method GetAreaFromName(areaName: string): int;
public static int GetAreaFromName(string areaName);

Parameters

areaNameName 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
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);
		}
	}
}
// NearestPointOnWater
using UnityEngine;
using UnityEngine.AI;

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.

Did you find this page useful? Please give it a rating: