Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

NavLocation.Equals

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

Declaration

public bool Equals(NavLocation other);

Parameters

Parameter Description
other A NavLocation to compare this one with.

Returns

bool true if both the node and the position of the two NavLocation values are equal, and false otherwise.

Description

Checks whether two NavLocation objects represent the same position on the same NavMesh node.

The comparison checks the node identifier and the exact position coordinates. Two NavLocation values that share the same node but have slightly different positions are considered different. Use this method to compare NavLocation values instead of relying on reference equality.

using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class NavLocationEqualsExample : MonoBehaviour
{
    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation a = world.MapLocation(transform.position, Vector3.one, 0);
        NavLocation b = world.MapLocation(transform.position, Vector3.one, 0);

        if (a.Equals(b))
            Debug.Log("Both samples landed on the same node and position.");
    }
}

Declaration

public bool Equals(Object obj);

Parameters

Parameter Description
obj An object to interpret as a NavLocation and to compare this one with.

Returns

bool true if both the node and the position of the two NavLocation values are equal, and false otherwise.

Description

Checks whether two NavLocation objects represent the same position on the same NavMesh node.

The comparison checks the node identifier and the exact position coordinates. Two NavLocation values that share the same node but have slightly different positions are considered different. Use this method to compare NavLocation values instead of relying on reference equality.

using UnityEngine;
using Unity.AI.Navigation.LowLevel;

public class NavLocationEqualsExample : MonoBehaviour
{
    void Update()
    {
        using NavWorld world = NavWorld.GetDefaultWorld();
        NavLocation a = world.MapLocation(transform.position, Vector3.one, 0);
        NavLocation b = world.MapLocation(transform.position, Vector3.one, 0);

        if (a.Equals(b))
            Debug.Log("Both samples landed on the same node and position.");
    }
}