- Home /
Having trouble checking if the player is in a trigger.
This is the code, what I'm trying to accomplish is set "inBox" to true when the player is inside a trigger, and if inBox is true, let the player left-click to 'Level up'. When I step inside the box, nothing changes. The box is an empty game object with a box collider component on it, "is trigger" is checked.
var level : int;
var inBox : boolean;
function onTriggerEnter(other : Collider) {
if(other.tag == "Player"){
inBox = true;
}
}
function Update(){
if(inBox){
if(Input.GetButtonDown("Fire1")){
level=(level+1);
}
}
}
Answer by Destran · Mar 22, 2014 at 04:26 PM
I think you need to capitalize onTriggerEnter to OnTriggerEnter
Wow, it's incredible how one missing capital letter can break your entire script. Thank you so much! This fixed it completely.
Answer by screenname_taken · Mar 22, 2014 at 04:23 PM
try var inBox : boolean = false; //just to make sure it's set to off.
also try Input.GetMouseButtonDown(0); instead.
Your answer
Follow this Question
Related Questions
if function broken? 3 Answers
Double click detection for gamepad triggers? 0 Answers
if statement not working 1 Answer
Trigger 'if' statement while in TextField 2 Answers
Making a sound play only once with a Boolean variable in javascript 1 Answer