CompareTag and OverlapSphere

I am currently trying to use CompareTag to test for an object in an array set up from an overlap sphere to see if it this the player. My code is as follows:

var colliders : Collider[] = Physics.OverlapSphere(transform.position, explosionRadius);
	for(var hit in colliders)
			if(hit.CompareTag ("Player"))

however this doesn’t seem to be working, I think the key reason for this is although i understand how each separate part of the code works, I don;t understand fully HOW it works, and therefor how it works together. I have looked through all of the appropriate script reference pages but I still don;t fully understand. If anyone was willing to explain how each part of this functions and the key reason(s) it isn’t working I would be eternally grateful.

Does your player have a rigidbody component? If you are using a character controller, then the answer is likely no. So in your code when you do this check for the player…


…will return false, and your player will not be found. This may or may not be your issue, but to figure out the problem either take a look in the debugger, or put some Debug.Log() calls as the first statements inside the for loop…just something like:

Debug.Log("->"+hit.tag+" - ";