Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity distance between 2 vectors 2d

Vector2.Distance(vector1.position, vector2.position);
Comment

unity distance between two vector3

Vector3.Distance(other.position, transform.position);
Comment

distance between two objects unity 2d

public GameObject object1;
public GameObject object2;
void Update()
{
  Vector2 Pos1 = object1.transform.position;
  Vector2 Pos2 = object2.transform.position;
  float x1 = Pos1.x, x2 = Pos2.x, y1 = Pos1.y, y2 = Pos2.y;
  // Distance between X coordinates
  float xDif = Mathf.Abs((Mathf.Max(x1,x2) - Mathf.Min(x1,x2));
  // Distance between Y coordinates
  float xDif = Mathf.Abs((Mathf.Max(y1,y2) - Mathf.Min(y1,y2));
  // Pythagorean theorem
  float finalDistance = Mathf.Sqrt(xDif * xDif + yDif * yDif);
  Debug.Log("Distance Between Object1 And Object2 Is " + finalDistance);
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to convert string to bool c# 
Csharp :: get program path c# 
Csharp :: how to get the directory of the project in c# 
Csharp :: vscode c# how to change to externial terminal 
Csharp :: c# convert dictionary to anonymous object 
Csharp :: add two numbers in c# 
Csharp :: c# int to bool 
Csharp :: get text between two strings c# 
Csharp :: c# string to double 
Csharp :: sconvert string to title case + C3 
Csharp :: unity get current scene 
Csharp :: manchester united 
Csharp :: c# randomize a list 
Csharp :: c# read file into a string 
Csharp :: isprime c# 
Csharp :: c# monogame mouse position 
Csharp :: compute months c# 
Csharp :: c# create array of number from number 
Csharp :: how to maximize but show taskbar c# 
Csharp :: even number checker in c# 
Csharp :: loadscene unity 
Csharp :: unity find closest point on line 
Csharp :: UnityEngine.Transform.get_position () (at <a0ef933b1aa54b668801ea864e4204fe:0) Gamekit3D.MeleeWeapon.BeginAttack (System.Boolean thowingAttack) 
Csharp :: get all assemblies c# 
Csharp :: how to say "Hello world" in c# 
Csharp :: animations for pause menu 
Csharp :: c# filter non alphanumeric characters 
Csharp :: visual studio windows form exit button 
Csharp :: c# const string array 
Csharp :: c# fizzbuzz 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =