Change scale joystick - 3 scripts

2 weeks and I dont know how… please help

I have problem - in hi-resolution and low-resolution screen Joystick touchpad in mobile is too small or too big.
I found some suggest and i’m writting easy scripts but not working:

  1. Script to change size GUITexture on Joystick:
function Start () {
if(Screen.width>330){
guiTexture.pixelInset.x = -234;
guiTexture.pixelInset.y = 0;
guiTexture.pixelInset.width = 234;
guiTexture.pixelInset.height = 234;
}}

Result:
GUITexture change size, but joystick not change, still have oryginal parametr.

  1. Script to scale GUITexture:
function Start () {
transform.localScale += Vector3(0.4, 0.4, 0.4);
transform.position=Vector3(1, 0, 0);
}}

Result:
GUITexture change size, but joystick not change, still have oryginal parametr.

  1. Script who check resolution then resize GUITexture and then add joystick script
if(Screen.width>330){
... (code from script 2)
	gameObject.AddComponent ("Joystick");
	}

Result: Character Controller hav’nt Joystick

How make it - 2 diffrent size touchpad joystick if low or hight screen resolution ?

try this:

transform.localScale+=Vector3(``1``,1``,1``)``;

trooper - your script not works: scale GUITexture but touchable position is still oryginal.

		transform.localScale += Vector3(0.5,0.5,0.5);

In attachment i put my simple project with this problem.
Is somebady who can change it ?

DOWNLOAD Simple Project - only 1MB :

For example:
if(Screen.width>400){
then size touchpad is 2x bigger

Thanks


Is somebody who know where is problem or what i must make to resize touchpad in script?

Maybe i must put to scene 2 Third Person Controller (first for low resolution and second for hi resolution) and script must active (with children) when chech screen resolution ?

But how active with children ?

Unfortunately, no one helps me.
No comments, no reply…

Fortunately, I was able to fix the problem yourself.
It works perfectly!

In Joystic.js I was correct:

  • defaultRect
  • defaultRect.x
  • defaultRect.y

and works very well!

Hey i was having the same issue, found this thread and you gave me an idea of how to approach this, however there was no clear solution. In case someone in the future finds this thread “gonna” post my solution.

attach this js script on some game object (it can be the joystick prefab itself) and drag the GUI Texture (the one that is attached to the joystick prefab) into the inspector variable.

public var t:GUITexture;
 
function Awake()
{
    var size = 0.18 * Screen.width;
    
    t.pixelInset.width = size;
    t.pixelInset.height = size;
    t.pixelInset.x = size/2;
    t.pixelInset.y = size/2;
}

this keeps the texture relative to the screen size. the .18 means that it will take 18% of the screen where the game is running. the setting on the inset.x and inset.y is for the texture never go off the screen, you can delete this and leave it at default 10px if you want.

A really really late reply, but i needed the exact same thing on my game.
Changing the guitexture via the normal pixelinset won’t work because the joystick script over-rides it.
Following on what przem997 said i just went and made defaultRect into public instead of private in the joystick script and just modified that through my own script depending on the needs of the device.
Works great.