- Home /
Question by
Humb · Jun 28, 2012 at 09:44 AM ·
buttontouchguitextureclick
GUITexture OnMouseDown Problem
In order to make GUITexture Click working for ios i used the following code. but cant succeed ?
for (var i = 0; i < Input.touchCount; ++i)
{
var touchObj : Touch;
touchObj = Input.GetTouch(i);
if(touchObj.phase == TouchPhase.Began)
{
if(lobjPlayTexture.guiTexture.HitTest(touchObj.position,lCompcamera))
{
//Doing Desired functionality
}
}
}
//lobjPlayTexture checking which GUITexture is clicked ..
Comment
PLease format your code by indenting it 4 spaces or 1 tab before pasting, or by highlighting it and click the code button after pasting. I've fixed it for you this time.
Answer by flamy · Jun 28, 2012 at 10:32 AM
I dont know what you are trying to do, but you can always use GUI.Button with image as a parameter
Texture _tex;
if(GUI.Button(Rect(),_tex,GUIStyle.none))
{
// your functionality
}
// note that the GUIStyle.none is important!
or if u still want to use GUITexture for a certain reason, is the ICompcamera non null??, does it work with Camera.Main as a parameter. and where is this piece of code in, i mean is it getting called regularly. and if nothing works try with Events on OnGUI
function OnGUI()
{
if(Event.current.type == EventType.MouseDown)
{
// your code here, since mouse down event will be called when a touch phase begins.
// This works even in ios!!.
}
}
yes its getting called repeatedly .
will this code work With GUITexture on ipad?
if(Event.current.type == EventType.$$anonymous$$ouseDown)