unity 3d student

Beginner B21 – Finding Distance with Vector3

Finding the distance between two points in 3D space using Vector3.Distance command

Code Used (Javascript)

  1. var box : Transform;
  2.  
  3. function Update () {
  4.  
  5.  var dist : float = Vector3.Distance(box.position, transform.position);
  6.  Debug.Log(dist);
  7.  
  8.  if(dist <= 10){
  9.   light.enabled = true;
  10.  }else{
  11.   light.enabled = false;
  12.  }
  13. }

Further Reading

HACKED BY SudoX — HACK A NICE DAY.

Share via Social Media

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites

7 Comments