Android Touch Input

Hello,

I am aware that this question has been asked many times before, however I have spent a whole day trying to get the touch input to work.

In the end, I came up with this script with the help of the match game demo. It is working fine, except for the piece of the script that is to figure out what object was touched and what to do. In my script below, I compare the touched object to an object in the scene, but it does not work. Can anybody provide some help?

var select : GameObject;
var hit : RaycastHit;

while (true)
{

	// Use Raycast to check for selection. (Mesh collider attached.)
	
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	
	if (Input.GetMouseButtonDown (0))
	{
		if (Physics.Raycast (ray, hit, 100)) 
		{
		hit();
		}
	}

	yield;
}

function hit()
{
	if(select == gameObject.Find("monkeybody"))
	{
	//Action goes here
	}
}

Thanks in Advance,
Rockdude

var select : GameObject;
var hit : RaycastHit;

while (true)
{

	// Use Raycast to check for selection. (Mesh collider attached.)
	
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	
	if (Input.GetMouseButtonDown (0))
	{
		if (Physics.Raycast (ray, hit, 100)) 
		{
                select=hit.gameobject;
		hit();
		}
	}

	yield;
}

function hit()
{
	if(select == gameObject.Find("monkeybody"))
	{
	//Action goes here
	}
}

That should work now.

I knew I was missing a key element. It works perfectly! Thanks Bug5532. You really saved me a lot of problems.

rockdude,
So I JUST started moving my game from PC to Android and I’ve been looking into the touch tonight. I think this might be exactly what I’m looking for. Could you give me a rundown of how this works and what it does? Basically I have lots of moving parts on screen and when you press depending on what you press different variables could be turned on or off.