- Home /
How do I get this texture to appear where I tapped/clicked?
I have an app and I want a texture(tappedCircle) to appear where my finger/mouse was when I tapped/clicked when gravity is false. Gravity becomes false when clicking/tapping.
So this works. It only appears when clicked/tapped, but my question is how to get it where the tap/click occurs. I assume since it's right on the screen (As it's OnGUI), there must be some form of coordinates that can be received from the tap/click, right?
void OnGUI()
{
if(gravity == false)
{
GUI.DrawTexture(new Rect(0,0, Screen.width * .085f, Screen.height * .15f), tappedCircle);
}
}
Answer by AnomalousX12 · Apr 10, 2014 at 11:47 AM
Instead of 0,0, use "Input.mousePosition.x, Input.mousePosition.y." If your game/app doesn't use multi-touch, mouse click code will work just fine for touch controls as far as I know.
Those coordinates will need some tweaking, but this will probably suffice.
Answer by Graham-Dunnett · Apr 09, 2014 at 08:26 PM
Look at the documentation for Input:
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html
The first example shows how you can record the position of the touch. Store that and use the result in your GUI code.
Your answer