Problem Detecting Collisions

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?

Sorry for double-posting, but I have more details on this issue now. Although the problem is still there while it is immobile, if I add a script that makes the attack buff move toward the tower, the collision is detected. So it seems the fact that it is stationary has something to do with the collision not being detected. Is there a way around this? Should I add the collision detection function to a script on the attack buff instead of on the player?

Does your player gameobject have a rigidbody component? Gameobject needs to have rigidbody to detect collision.

Oh wow. Yep, that’s it. I put a rigidbody component on the attackBuff, but not on the player. >_< Thank you for your help!