Detecting an object being hit on iphone doesn't work

I have little devils that I want to kill when someone touches them on an iphone screen. Heres the code. Each object in the game has this code attached to it. Can anyone explain why it kills them all if I touch one of them and how to only kill the one that was touched??

Thanks in advance.

In function Update:

for (var i = 0; i < Input.touchCount; ++i) {
	if (Input.GetTouch(i).phase == TouchPhase.Began)
		{
		var MyCast : RaycastHit;
		var ObjectHit : GameObject;
		var ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
		if(Physics.Raycast(ray,MyCast,100))
			{
				ObjectHit = MyCast.collider.gameObject;
				ObjectHit.SendMessage("OnMouseDown");
				//transform.gameObject.SendMessage("OnMouseDown");
			}
		}
}

then:

function OnMouseDown ()
{
	var Smoke = gameObject.transform.FindChild("Smoke");
	var Body = gameObject.transform.FindChild("character");
	
	HitPoints = HitPoints - 1;
	if(HitPoints <= 0)
	{ 
		Body = Body.transform.FindChild("ROOT");
		//Debug.Log(Body2);
		if(DevilCanMove == true)
			{
			PlayerPrefs.SetInt("CurrScore",(PlayerPrefs.GetInt("CurrScore") + 10)); //increase the score
			}
		DevilCanMove = false; //stop running
		transform.rotation = Quaternion.LookRotation(Vector3(0,1,0)); //look up when you die little devil
		animation.Play("gets_killed"); //lay down and die!!
		Smoke.active = true;
		yield WaitForSeconds (1);
		Body.active = false;
		yield WaitForSeconds (1);
		Smoke.active = false;
		//yield WaitForSeconds (2); //wait to make the player happy
		Destroy(gameObject); //poof - devil is gone
		gameGUI.ReduceDevils(); //reduce devil count for end of level
	}
	else
	{
		DevilCanMove = false;
		animation.Play("getting_hit");
		yield WaitForSeconds(.5);
		if(DevilCanMove == false)
			{
			PlayerPrefs.SetInt("CurrScore",(PlayerPrefs.GetInt("CurrScore") + 10)); //increase the score
			}
		DevilCanMove = true;
	}
}

I would put some prints in to see where the info is getting to, and not.

not sure I understand. I can tell that it is registering the hit, and then sending the message to the mouse down. I just can’t seem to isolate the one devil that was hit from getting killed. Right now, any devil getting hit, causes all devils to die. :frowning:

This doesn’t sound like a code issue. What it sounds like to me is that you’re hitting a collider that happens to have all the devils as children. There’s no real way to make sure, of course, until you Debug.Log(collider.transform.name); and find out what’s being tapped for sure.