Reputation: 1155
I'm a beginner in Unity3d and I'm trying to measure the distance between two game objects (spheres). For this, I did at first a line and then, I measured the distance between the two objects using Vector3.Dstance(). However, I got a result 6.4 and I'm not sure if this distance that I measured is in meters or which unit hass the result (Vector3.Distance) that I got. I would appreciate your help.
using UnityEngine;
public class Line : MonoBehaviour {
public GameObject gameObject1;
public GameObject gameObject2;
private LineRenderer line;
// Use this for initialization
void Start () {
line = this.gameObject.GetComponent<LineRenderer>();
line.startWidth = 0.05f;
line.endWidth = 0.05f;
//line.SetVertexCount(2);
}
// Update is called once per frame
void Update () {
line.SetPosition(0, gameObject1.transform.position);
line.SetPosition(1, gameObject2.transform.position);
float distance = Vector3.Distance(gameObject1.transform.position, gameObject2.transform.position);
Debug.Log(distance);
//Debug.DrawLine(gameObject1.transform.position, gameObject2.transform.position, Color.red);
}
}
Upvotes: 1
Views: 3265
Reputation: 35663
These are "game units". Units are whatever you choose them to be, it's all relative.
If you want them to be 1 metre, then you make in-game objects which should be 1 metre equal to 1 game unit, and in-game objects which should be 30 cm, equal to 0.3 game units.
Upvotes: 5