- Home /
 
Duplicate Question
Very simple picking up items script?
Hi! I have a flashlight laying on the ground and I want it to be so when the player collides with it, they will be able to use the flashlight.
I tried to look up the answer for myself, but all the answers I could find involved complicated inventory scripts and gui's and stuff. I just want a very simple way to pick up and use a flashlight. Thanks for any advice :)
Answer by superventure · May 26, 2013 at 05:59 AM
use trigger functions on the item. for example
     function OnTriggerEnter(other : Collider){
     if(other.gameObject.name == "Player"){
     transform.parent = PlayersHand.transform;
     transform.position = PlayersHand.transform.position;
      }}
 
               You need to a box collider set to trigger on the flashlight or any object
You'll need a collider on the player too, to collide with the flashlight's collider.
If i put the collider on trigger it falls through the ground how do i go arround this?
Answer by TheRichardGamer · May 26, 2013 at 07:55 AM
Try this :
 //This is the script for the player
 var Visible : boolean = false;
 var light : Light; 
 var FlashLight : GameObject;
 
 
 
 function Update () {
 
 if(Visible == true){
 
    light.enabled = true;
    FlashLight.enabled = true;  
 
 
    }
 }
 
 
 //This is the script for the flashlight
 
 var otherScript : <player_script_name_here>;
 
 function OnTriggerEnter (other : Collider){
 
 
  if(other.gameObject.tag == "Player"){
   otherScript.Visible = true;
 
 
 
 
     }
 
 }
 
              Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Scripts were perfect but now they are all messed up please help 0 Answers
Help with pickup script 0 Answers
I need help instantiateing a bullet 0 Answers