- Home /
Question by
fedqx · Aug 13, 2017 at 08:58 AM ·
unity 5triggerupdate function
How to press a button in trigger ?
Hello developers ! I am going to make a money-collection system but i have a problem. The player should walk in the Money's trigger and press "g" key to collect money and that will give the player 2$ but i cant use ontriggerenter
in update
function and i cant use update
in ontriggerenter
function Can you DEVELOPERS help me to solve my problem ?
Comment
Best Answer
Answer by as30050273 · Aug 13, 2017 at 09:09 AM
Hello! You need to initialize 1 more boolean variable, which will help you to understand, if player now is in trigger zone.
boolean inTrigger = false;
void Update(){
if(inTrigger){
//here you can check if player pressed 'g' button and collect money
}
}
void OnTriggerEnter(Collider col){
inTrigger = true;
}
void OnTriggerExit(Collider col){
inTrigger = false;
}