- Home /
Only tagged objects raise counter
Hello,
I have objects that move through a trigger, and in doing so raise a counter - which in turn loads a new scene when it hits the right ammount.
However, the problem I am facing is that any object with a collidor on will raise the counter, instead of just these characters.
What I am hoping to have is only colliders with a specific tag (In this instance, box.) to effect the coutner trigger.
As far as I know, it SHOULD work with the following, but for some reason it dosn't Items with other tags or no tags still effect it.
Anywhere, here is the script:
var score : int = 0;
var customButton : GUIStyle;
function OnTriggerEnter (other: Collider){
if(gameObject.tag == "box")
score += 1;
}
function OnGUI () {
GUI.Label( Rect(10, 10, 2000, 2000), "Escaped: " + (score), customButton);
}
function Update () {
if (score == 4) Application.LoadLevel("level1");
}
Answer by Berenger · Mar 08, 2012 at 12:04 AM
You are not checking the correct tag. You are checking the tag of the gameobject that script is attached to, which will remain the same not matter what. Check other.tag instead, this is the collider that enter the trigger.