Hla, long time listner, first time caller ;)
I am making a bejewel clone with a twist ;) for the android platform. But I am a little unsure how I get hold of the sprite after a finger touch. Time for some code. (snippet is from Update)
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
Ray gemRay = Camera.main.ScreenPointToRay(touch.position);
if(Physics.Raycast (gemRay, out hit))
{
if(hit.collider.gameObject.tag == "Gem")
{
AudioSource.PlayClipAtPoint(ClickSound , hit.point);
//Highlight the selected Gem if it is the first one pressed
print("Gem hit");
}
}
}
}
As you can see I need to get hold of the sprite which contains the selected gem, so I can highlight/animate/remove it.
I though of putting the spirte into the Gem script as a public var or perhaps use an ID in the tag and run through all the sprites and find the corresponding sprite to the gameobject. But there most be an easier way.. :)
Thanx, I tried that before I posted yesterday, but I guess I most have been tired since I couldn't get it to work back then. I tried "(hit.collider.gameObject.GetComponent<Gem>()).sprite.hidden = true;" just now, and it works like a charm..
– anon44920774