- Home /
Item pickup and activating an item afterwards help
Basically im making an indie horror game, and im a beginner to scripting. I want my player to be close to the pickup and itll say "press 'e'" and i got it all working apart from one thing. My flashlight either stays disabled or stays enabled from the start. Heres my script so far:
#pragma strict
var player : Transform;
var gui : Transform;
public var target : GameObject;
function Start () {
gameObject.SetActive(true);
gui.guiText.text = "";
target.active = false;
}
function Update () {
var dist = Vector3.Distance(player.position, transform.position);
if(dist<2)
gui.guiText.text = "Press 'E' To Pick Up The Flashlight";
if(dist>2)
gui.guiText.text = "";
if(Input.GetKeyDown("e") && (dist<2))
gameObject.SetActive(false);
}
Answer by CoreyRB · Oct 31, 2013 at 07:01 PM
I have never done an inventory system before so I might be completely wrong on this, but have you tried using gameObject.SetActiveRecursively instead of gameObject.SetActive ?
Answer by SUBSONICuk · Oct 31, 2013 at 07:29 PM
i fighured it out now, it turned out I needed
if(Input.GetKeyDown("e") && (dist<2))
gameObject.SetActive(false);
if(Input.GetKeyDown("e") && (dist<2))
target.active = true;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I'm making a horror game and I need help with item pickup 1 Answer
How to make a animation rotation js.script? 2 Answers
I'm trying to add items to an inventory. 1 Answer
How to pickup and equip an object? 0 Answers