Hi, everyone. I’m having some trouble getting cubes to detect collisions. I’m following along with a series of tutorials and I’m at a part where I want my player character to get an attack power boost when he runs into a cube. When the collision occurs, it should log in the console “hey” and the player’s new attack power. Here’s JavaScript for that:
function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "minionAttack") {
curHp -= 10.0;
Debug.Log("ouch!");
}
if(col.gameObject.tag == "attackBuff") { //this is the collision I'm referring to
Debug.Log("hey");
attackBuff();
}
}
function attackBuff () {
maxAttack += 10.0;
Debug.Log(maxAttack);
yield WaitForSeconds(10);
maxAttack -= 10.0;
Debug.Log(maxAttack);
}
I create a 5x5x5 cube and add the tag “attackBuff”, check the Is Trigger checkbox for the Box Collider component, and run the game. When I walk through the box, nothing happens in the console and there are no errors. I removed the function from the script so that there was just the Debug.Log statement, but that didn’t change the result, so clearly the collision wasn’t being detected. I then went and set my enemy fireball prefab (which is being shot at a tower during the game) to the tag “attackBuff” and I was surprised to see that it works. Normally the fireballs reduce the player’s health by 10 points for each collision, but when I changed the tag, I got my desired console log statements. I tried attaching the tag to a few other game objects, like the tower, a tree, and a capsule, but nothing seems to work except for the enemy attacks. Could anybody give me some insight on what might be causing this?