Check Distance - OuterRimStudios/Utilities GitHub Wiki

MathUtilities.CheckDistance

public static float CheckDistance(Vector3 point1, Vector3 point2)

Parameters

point1 The first point of the distance calculation.

point2 The second point of the distance calculation.

Returns

float distance between the two points.

Description

Calculates the distance between two Vector3 positions.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        Vector3 targetLocation = new Vector3(0, 0, 10);
        transform.position = Vector3.zero;
        float distToTarget = MathUtilities.CheckDistance(transform.position, targetLocation);    //Returns 10.0f
    }
}

public static float CheckDistance(Vector2 point1, Vector2 point2)

Parameters

point1 The first point of the distance calculation.

point2 The second point of the distance calculation.

Returns

float distance between the two points.

Description

Calculates the distance between two Vector2 positions.

using UnityEngine;
using OuterRimStudios.Utilities;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        Vector2 targetLocation = new Vector2(10, 0);
        transform.position = Vector2.zero;
        float distToTarget = MathUtilities.CheckDistance(transform.position, targetLocation);    //Returns 10.0f
    }
}