I’ve made a color picker for an iOS app where the user can tap on a color and the color is passed to a GameObject which is then instantiated, so for instance if the user taps the color blue, a blue cube appears.
It seems that OnGUI() is an expensive call to make with iOS so I’m trying to get my working code into a more performance friendly Update().
The problem I have encountered is if I use a Texture2D instead of a GUITexture, I can’t figure out how to use HitTest like this:
if (Input.touchCount>0)
{
for (var touch : Touch in Input.touches)
{
if(touch.phase == TouchPhase.Began && gui.HitTest(touch.position))
{
// Just touched the GUITexture
frame.renderer.material.color = Color.red;
Debug.Log("TouchGUITex");
}
}
}
If I use a GUITexture, I loose the ability to sample a color and pass it to a game object using GetPixel:
var col : Color = colorPicker.GetPixel(pixelPosX,pixelPosY);
cubecol = col;
var cube = Instantiate(blockPrefab, Vector3(0,0,0), Quaternion.identity);
cube.name = "Cube1_"+cubecnt.ToString();
cubecnt++;
cube.renderer.material.color = cubecol;
Not sure, but it seems I may be stuck using OnGUI() along with a Texture2D if I want to keep the ability to use GetPixel, is there any less expensive way of solving this? Thanks!