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)

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

Further Reading

Share via Social Media

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

7 Comments