Hello, I am a programmer, mostly focused on functionality scripts. I’d like to make GUI, but I am not sure how to make GUI a little bit different on phone or Xbox. Is there any way to do it? Thank you.
By looking different on other platforms, do you mean in size so it fits or do you want a separate UI for different platforms?
Yes, i mean size, and also different layouts for Xbox (you will be able to see button controls, ie. to Horn press X)
I’m confused on that last part, maybe you could elaborate a bit more?
If you’re in a vehicle you will be able to see what button you should press. (ie. if you’re on pc it would be H, on phone you will click the button and on Xbox it would be X.) I’ll use the GUI to show the picture of the button. It would be different on each platforms.
To determine different platforms, you can use UserInputService and GuiService.
There are properties such as a property which allows you to see if the device has a gyroscope or not. This would be for mobile.
For the console checks I would look for a gamepad connected and the method IsTenFootInterface
which returns a bool.
For PC checks there’s a property called KeyboardEnabled & MouseEnabled in the UserInputService service.
You can just store the LocalPlayer’s platform in a table in a module so you can access other player’s platforms too, oh the power of tables, and for the different buttons you can just replace their ID depending on the platform.
Have a good one,
cc. OP @Fliper05YT
While this is a common approach to this problem, unfortunately it is not a good one.
- The presence of a gyroscope is not enough information to determine that the user is playing on a mobile device.
- You are confusing ‘using an Xbox’ and ‘using a gamepad’ - OP mentions wanting to make controls adapt to the player, and not all gamepad users are on Xbox.
- KeyboardEnabled and MouseEnabled also do not reliably indicate that a user is playing on a PC.
As well as this, these checks are concerned with the wrong things. You have been attempting to detect what ‘platform’ the user is playing on, but OP really should be determining what type of input the user is providing. A player ostensibly using their PC may in fact be playing with a gamepad, for example.
Furthermore, your approach does not pay any attention to when input types change during gameplay (this does happen!), for example a PC player plugging in a gamepad after they have joined, or unplugging one and switching to keyboard & mouse. It is very important to listen for this, so caching a player’s platform is not a great idea.
You can read more on this topic and get some code samples here: Programming cross-platform compatible UI by detecting input peripheral changes.
Thank you for your response, I’ll check it out. Have a great day.