- Home /
iphone OnGUI define and test within rect??
I know that OnGUI is in general a bad idea within iOS apps; however, my scenes are very simple and OnGUI has no noticeable effect to the user within game, and I'm trying to speed things along as a novice programmer.
The problem is with multitasking using OnGUI. I have a single fire button on the left side of the touch screen, but if the user first rests a finger or two on the right side (area without button), the fire button won't work. So I suppose that testing for a finger touch within the OnGUI button would fix this.
//If GUI.Button && if touch within GUI rect then fire.
The following is my code so far minus my not working efforts to get touches and test touches within the given rect. I really need a code example to learn from. Any help is appreciated. Please help me with OnGUI. I know of all the alternatives, but this code is working and I'm otherwise pleased. I think it could help others as well. (I've tried GUITextures but am having trouble getting them to work as well.) :
var prefabBullet:Transform;
var customButton : GUIStyle;
function OnGUI () {
if(GUI.Button (Rect (0,Screen.height*.6-64,128,128), "", customButton))
{
instanceBullet = Instantiate(prefabBullet , transform.position, transform.rotation); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613085202im_/https://answers.unity.com/themes/thub/images/avi.jpg)