Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

NavMeshAgent.CompleteOffMeshLink

Switch to Manual
CompleteOffMeshLink(): void;
void CompleteOffMeshLink();
def CompleteOffMeshLink() as void

Description

Follow the current OffMeshLink.

When the autoTraverseOffMeshLink property is switched off an agent will pause at an off-mesh link until this function is called to let it pass. This can be used to allow characters access selectively (eg, to simulate openable doors or obstacles that only certain characters can pass, etc).

	private var agent: NavMeshAgent;

function Start () { agent = GetComponent.<NavMeshAgent>(); } // Let an agent cross the off-mesh link if he has // the right door key. function CheckForDoorKey(doorKeys: Hashtable) { if (agent.isOnOffMeshLink) { if (doorKeys.ContainsKey(agent.currentOffMeshLinkData.offMeshLink.name)) { agent.CompleteOffMeshLink(); } } }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    private NavMeshAgent agent;
    void Start() {
        agent = GetComponent<NavMeshAgent>();
    }
    void CheckForDoorKey(Hashtable doorKeys) {
        if (agent.isOnOffMeshLink)
            if (doorKeys.ContainsKey(agent.currentOffMeshLinkData.offMeshLink.name))
                agent.CompleteOffMeshLink();
            
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private agent as NavMeshAgent

	def Start() as void:
		agent = GetComponent[of NavMeshAgent]()

	def CheckForDoorKey(doorKeys as Hashtable) as void:
		if agent.isOnOffMeshLink:
			if doorKeys.ContainsKey(agent.currentOffMeshLinkData.offMeshLink.name):
				agent.CompleteOffMeshLink()