- Home /
 
               Question by 
               blackpantherxx · Sep 22, 2012 at 03:06 PM · 
                objectgameend  
              
 
              End game then an Object is close to another object?
In my game you need to pick up a key to a car, then get to the car, and then you "escaped" and won the game. Is there any way that i can do this so then the key is near to car the game is over. Maybe it displays a text if that is possible. This is a big ask, but got really no idea of how to do this. And couldt find any thing.
Used this script to pick up key:
 private var pickObj: Transform = null;
 private var hit: RaycastHit;
 private var dist: float;
 private var newPos: Vector3;
 
 function Update(){
 
     if (Input.GetMouseButton(0)){ // if left button creates a ray from the mouse
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (!pickObj){ // if nothing picked yet...
             if (Physics.Raycast(ray, hit) && hit.transform.tag == "Pick"){
                 // if it's a rigidbody, zero its physics velocity
                 if (hit.rigidbody) hit.rigidbody.velocity = Vector3.zero;
                 pickObj = hit.transform; // now there's an object picked
                 // remember its distance from the camera
                 dist = Vector3.Distance(pickObj.position, Camera.main.transform.position);
             }
         }
         else { // if object already picked...
             newPos = ray.GetPoint(dist); // transport the object
             pickObj.position = newPos;   // to the mouse position 
         }    
     }
     else { // when button released free pickObj
         pickObj = null;
     }
 }
Picked it up in amnesia style.
Please please help ;)
               Comment
              
 
               
              to find a distance, just use Vector3.Distance. check out the doco for that call.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Slicing Objects 1 Answer
get all scripts attached to gameobject 2 Answers
FPSMouseScript.js 1 Answer
Help; I have two code errors need adivce 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                