They do not work within my game and I’m wondering what else might be wrong. Any feedback anyone has to offer will be appreciated.
Attached to my main camera I have four guiTextures, main_menu_1, main_menu_2, main_menu_3, main_menu_4. When the game loads on the iPod these are displayed as menu buttons on the screen. Attached to main_menu_1 is a script called button_press_1 which was taken from the above example and is:
var level : String;
var recoveryTime = 10;
private var delay = 0;
function Update () {
if (delay>0){delay -=1;}
if (delay==0){
if(Input.touchCount == 1){
var currentTouch:Touch = Input.touches[0];
Application.LoadLevel(level);
delay = recoveryTime;
}
}
}
I had hoped that touching this button would take the player to the next level of that game as it does in the MacOS player but instead nothing happens regardless where I touch on the screen.
Can someone provide a working version of detecting a touch on the guiTexture with Unity3.4 or at least explain what I am doing wrong in the above example?
Yes we call Application.LoadLevel(level); and we define the variable level via the inspector. We also assign this to a guiTexture so we really want to know when a hit is registered against a specific area on the screen.
We did try the hit test in a different version of the script. That version contained the following and was taken from a message in the forums that purportedly worked with the previous version of Unity.
function Update () {
if (delay>0){delay -=1;}
if (delay == 0){
if (iPhoneInput.touchCount ==1){
var currentTouch:iPhoneTouch = iPhoneInput.touches[0];
I use this crude method to pickup single screen presses on iphone/ipad:
//check buttons here!
if (Input.GetMouseButton (0) ){
var mx = Input.mousePosition.x;
var my = Input.mousePosition.y;
print(" MOUSE.... mousex=" + mx + " mousey=" + my); //print mouse coords for debug
//Button 0 (top left)
if ( mx>68 mx<313 my>387 my<585)
{
do what ever in reaction to button...
its not multi-touch but it works, both on the Mac when coding and on the device.
Thanks. We actually have a touch script working. It was not the script but the number of images unloaded when moving from the main menu to the game menu that caused so much delay it seemed the touch was not working. Adding some debug output to the script and monitoring the xcode console clearly showed the cause of the delay.