Unity Turtorial: 24 How can I find the distance from one object to another using raycasts?

Advertisemen

Unity Turtorial: 24 How can I find the distance from one object to another using raycasts ?







Unity3D TUTORIAL: 24 Find the distance from one object to another!

THIS IS Java script: GOOD 4 2D GAMES AND 3D GAMES ! 
----------------------------------------­­­­­­­----------------------------------­-­-­-­-­-­-­------



DIRECT DOWNLOAD HERE


----------------------------------------­­­­­------------------------------------­-­-­-­-­-

THIS IS BACKUP  IN TEXT FORM  TUTORIAL 23

1. Create New java and name it :
DISTANCE

2. Copy & Past this text and save java :
----------------------------------------­­­­­------------------------------------­-­-­-­-­-

#pragma strict

 var target: Transform; // planet transform
 private var distance: float;
 
 
 function FixedUpdate(){
   // get current position:
   var myPos: Vector3 = rigidbody.position;
   // create ray from this object to the planet center:
   var ray: Ray = new Ray(myPos, target.position - myPos);
   var hit: RaycastHit;
   // do a Raycast that sees only the target collider:
   if (target.collider.Raycast(ray, hit, Mathf.Infinity)){
     // save distance to the surface in variable distance:
     distance = hit.distance;
   }
 }
 
 function OnGUI(){
   // show the distance with one decimal digit:
   
   GUI.Label(Rect(10,10,120,30), distance.ToString("F1"));
 }



----------------------------------------­­­­­------------------------------------­-­-­-­-­-

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D