Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Distance(Vector3, Vector3)

Returns the distance between a and b.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static float Distance(Vector3 a, Vector3 b)

Parameters

Returns

Type

Description

float

Remarks

Vector3.Distance(a,b)
is the same as
(a-b).magnitude
.

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public Transform other; void Example() { if (other) { float dist = Vector3.Distance(other.position, transform.position); print("Distance to other: " + dist); } }}