fedqx
1
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 ?
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;
}