problems with trigger,some doubts about my script / algumas duvidas sobre o meu script
i dont know how to show to my script what is the gameobject he is triggering, to give to the player different valors of gold, which depends on what box the player trigger.
void OnTriggerEnter2D(Collider2D col){
if (col == Bau1) {
Ouro += 1;
Destroy (col.gameObject);
print (Ouro);
}
if (col == Bau3) {
Ouro += 3;
Destroy (col.gameObject);
print (Ouro);
}
}
}
,i created a void OnTriggerEnter2D to my character get gold after trigger on the box, and then destroy it, and i got it, but in my game i spawn 2 kind o Boxes, a Red box and a gold box. the red box give the player 1 gold, while the gold box give 3 golds. my instantiate already spawn the both box, but i cant made my system know which box he got and send the different instructions for it.
void OnTriggerEnter2D(Collider2D col){
if (gameObject = Bau1) {
Ouro += 1;
Destroy (col.gameObject);
print (Ouro);
}
if (gameObject = Bau3) {
Ouro += 3;
Destroy (col.gameObject);
print (Ouro);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612200222im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I collect collider2Ds(Trigger) the player is in into an array 1 Answer
Trigger detects player collision and play specific audio from array 1 Answer
Trigger events work twice at same time 0 Answers
Enable Multiple Box Collides From Parent Object 2 Answers
How do you rotate objects at the same time using arrays and triggers 0 Answers