- Home /
How to change button sizes depending on iOS device?
Hi everyone,
I am using code similar to the following to change button scale and position depending on whether the user has an iPhone or iPad... but it doesn't work. What am I doing wrong?!?!?!
function Start ()
{
if (iPhoneGeneration.iPhone3GS ||
iPhoneGeneration.iPhone4 ||
iPhoneGeneration.iPhone4S (...and so on)
)
{
// Pos x, pos y, height, width. Using screen height for both assures button doesn't deform
GasButton.pixelInset = Rect (-64, -64, (Screen.height / 4), (Screen.height / 4));
GasButton.transform.position.x = 0.93;
GasButton.transform.position.y = 0.15;
}
else if (iPhoneGeneration.iPad1Gen ||
iPhoneGeneration.iPad2Gen ||
iPhoneGeneration.iPad3Gen ||
iPhoneGeneration.iPadUnknown)
{
// Pos x, pos y, height, width. Using screen height for both assures button doesn't deform
GasButton.pixelInset = Rect (0, 0, (Screen.height / 8), (Screen.height / 8));
GasButton.transform.position.x = 0.82;
GasButton.transform.position.y = 0.4;
}
}
I should add, for the Android version of the game, the user can select whether they have a phone or a tablet, using the same code above, basically, and it works fine. It's the iPhoneGeneration enumeration that doesn't seem to be working for me...
Euh, "never use "else if" in program$$anonymous$$g." is a personal point of view that I think might not be shared by most programmers.
$$anonymous$$arl, what is not working?
What's wrong with using if else statements? I don't see why that would break the code... and I love globals! I'm lazy (and nobody else sees my code)! Hahaha.
I'll give yours a go, but I am at a loss as to why my code isn't working... do I need to run it right upon loading of the app? As it stands, that script is called just before the buttons are placed on the screen.
I'm not in the program$$anonymous$$g field, I do it out of necessity. Hard to find coders to work for free! Still... I have a game out and none of the players know what's in the code, so as long as it works I use it :P I won't use globals when coding in C++ generally, but I'm not quite sure I could avoid using them in Unity...
Still... the original issue stands... for some reason, this code is not working...
Answer by kumarc123 · Apr 07, 2014 at 01:47 PM
Hello,
Check out this link. It is actually in Chinese. Google will help in translating it into English. This will give you details about why you can't solve your problem and also the possible solution to it. The site also has some useful tutorials about Unity. Hope this may help...
Your answer
Follow this Question
Related Questions
Ampersand in application name 4 Answers
Pinch vs. Rotate gestures: can they be made size/resolution-independent? 2 Answers
Are soft shadows supported on iOS ? 2 Answers
need help launching game to app store 1 Answer
iphone ios version and sdk version 1 Answer