- Home /
 
               Question by 
               tom1103 · Oct 13, 2012 at 03:30 PM · 
                pickupflashlight  
              
 
              Help with pickup script
Here's my script:
 var flashlight1 : GameObject;
 var flashlight2 : GameObject;
 
 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 nothing picked yet...
             if (Physics.Raycast(ray,hit){
                flashlight1.SetActiveRecursively(false); 
                flashlight2.SetActiverecursively(true);
             }
             
         
         else { // if object already picked...
              flashlight1.SetActiveRecursively(true);
              flashlight2.SetActiveRecursively(false);
         }    
     }
   
 }
               Comment
              
 
               
              What problem are you having? Your ray cast can hit anything and if it does you disable flashlight1 and enable flashlight2. Otherwise, you enable 1 and turn off 2. That sounds a bit weird to me. Also you have SetActiveRecursively spelt wrong the second time you use it.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Very simple picking up items script? 2 Answers
How to pickup and equip an object? 0 Answers
Flashlight pickup, battery etc 3 Answers
Problem with ligths! 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                