- Home /
How to draw a line between objects and get distance
Hi Everyone,
Im just working on my enem behavior script. For debug reasons I want a red line from the enemy drawing to the player. I tried Debug.DrawLine but i somehow cant get it to work o.O
Also I want to get the distance between the two objects, how can I do that?
Thanks in advance!
Answer by BiG · Jan 31, 2012 at 09:51 AM
Debug.DrawLine seems the best solution, maybe you can post the code to let us view how you've used it.
To get the distance between two objects you can do that:
Vector3.Distance(object1.transform.position, object2.transform.position);
Hello, Thanks for your answere. I tried this code Debug.DrawLine(transform.position, gameObject.Find("Player").transform.position, Color.red,100.0); Now I see what my problem is, I want this "Debug" line also visible in the game view. I now recognized it is visible in the Scene view. How can I do that? :) Thanks in advance.
The result of Debug.DrawLine is only visible in the Scene View, by default. If you want it in the Game View, you have to enable Gizmo Drawing. Look here: http://forum.unity3d.com/threads/11707-Gizmo-Drawing, $$anonymous$$atthew's answer should be useful.