Distance Between 2 objects (Unity3D)

bagiryu Étiquettes : , , , , , ,
To Find the distance between two objects in unity 3D, you need to use a simple method call Vector3.Distance();. You can download the unity Project By following this link

>>>Download<<<

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Lerp_Script : MonoBehaviour
{
    public GameObject obj1;
    public GameObject obj2;
    public float Distance;
    public GUIStyle style; 

    // Start is called before the first frame update
    void Start()
    {
        style.fontSize = 50;
    }

    // Update is called once per frame
    void Update()
    {
        Distance = Vector3.Distance(obj1.transform.position, obj2.transform.position);
    }

    private void OnGUI()
    {
        GUI.Label(new Rect(50,150,200,200), "Value :" + Distance, style) ;
    }
}

Post you may be interested...

Import 3D asset within a game (Unity 3D) , Distance Between 2 objects (Unity3D) , ...

there are no comments yet ! be the first !

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *