- Home /
Question by
Oobi23 · May 31, 2013 at 01:35 AM ·
destroyontriggerenter
Different scores with OnTriggerEnter Destroy
hi there guys, So I am trying to destroy two different objects that gives different scores using the same character. Here is the coding so far. The tag "blackBox" works, but not the "rainDrop". what am I doing wrong?
static var score = 0;
function OnTriggerEnter (other : Collider){
if(other.tag == "blackBox"){
score +=5;
Destroy(other.gameObject);
}else{
if(other.tag == "rainDrop")
{
score +=1;
Destroy(other.gameObject);
}
}
}
Comment
Answer by bodec · May 31, 2013 at 01:51 AM
Using the else stamen means only one of those two will be destroyed as only one condition can be true. even thou both may be true the if stamen returns true and it will ignore the else statment
remove the else statement so it reads
function OnTriggerEnter (other : Collider){
if(other.tag == "blackBox"){
5. score +=5;
Destroy(other.gameObject);
}
if(other.tag == "rainDrop")
{
10. score +=1;
Destroy(other.gameObject);
what that does is give the score an extra score 1 at the start. It still works for blackBox.
Then you are hitting both triggers do you have a picture of what you are trying to achieve