Detecting Click/Touch in Unity iPhone (SpriteManager)

Hi all,

I apologise now if this question doesn't belong here given that it's related to SpriteManager.

I'm using SpriteManager for all of my on-screen graphical elements and I need to be able to detect touches on my sprites, for the sake of screen progression and interface interactions (muting auto for example, by clicking on the audio sprite). Each sprite is attached to its very own plain GameObject, currently with no way of detecting a hit on a sprite. In the past I have used GUITextures which come with a 'HitTest()' method. Sadly, the current project i'm working on requires a LOT of sprites, so GUITexture is too inefficient this time around because of the draw calls.

Any advice greatly appreciated as always.



There are a couple of ways to go here. For one, EZ GUI operates seamlessly with SM2 (though it does not require it) to do sprite-based UI like it sounds like you are wanting to do. However, if you want to use strictly SM2, you can add a collider to your sprite object and then do a raycast from the point that was touched. Just get the touch or mouse click, and then use your camera's ScreenPointToRay() to get a Ray from the touched point, and then pass this to Physics.Raycast() and from there you can find out info on what was hit, if anything.