last day (15 days later) » 

11:07 AM
1
A: Issue with Keyboard controls in release - not occurring in unity editor

cmprogramThis is not how you should implement your menu within Unity. It is CPU intensive to create and destroy game objects, and it becomes difficult to track when you do on a recurring menu or object, especially as your project expands. Instead, have a single Main Menu Game Object, named "Main Menu Can...

 
I'm using physical gameobjects with text mesh currently and raycasting to check for click, should i be using a canvas ?
 
@DylanRobertson Absolutely. It might take a wee bit of time for you to get it figured out, but trust someone who has developed numerous game in Unity - the canvas will ensure your UI is consistent, and well organised.
 
While i have you here could i get some clarification on Scaling ? whats the easiest way to just make everything shrink to fit the screen ? i don't mind black bars
 
@DylanRobertson Not to bang on about it, but the Canvas handles this. If you develop your UI to a sized reference e.g 1920 * 1080, then you can specify IF it should scale, and by height OR width as a priority. Then you can anchor your game objects to ensure they appear appropriate to other UI elements, regardless of the scale. There is no need for black bars, at all.
 
Is it possible to convert already made objects into canvas with conserved scripts ? i have already made all my ui.
 
11:07 AM
Are your current GameObject's that you're using, Sprites?
 
I believe so, here are some pics. prntscr.com/mujc4x , prnt.sc/mujbyn
hello
 
Hi there, just moved this to chat to save spamming the question with comments
 
no problem
 
Okay, so I've not done it in this manner before
But theoretically
You could click on btnLeft, hold shift and then click on your bottom ui element
Then go to Add Component -> Image()
(You may need to remove the Sprite Renderer for this to work, but maybe not - I'm actually at work just now and don't have Unity in front of me)
Then, go through and find your buttons, and add component -> button()
 
ok so i added an image to all the children
 
11:11 AM
Then, go to create at the top, create canvas
Then drag all of your children onto that canvas
Set Canvas Camera to Main Camera
And sort the scaling, and then you should be good to go, or at least on your way there
 
how do i Set Canvas Camera to Main Camera ?
render mode ?
 
So click on your Canvas Object
Let me just remind myself
Yes, Render Mode
Change it to Screen Space - Camera
Then select the Main Camera in your scene
(Where it says Render Camera)
 
ok so my objects seem to have disappeared
 
Don't worry about it
Do you mean they aren't rendering on the screen, or they are physically gone from the inspector
?
 
they are gone from the inspector
rather they are verrrry small
 
11:17 AM
The inspector means the list of objects
They aren't gone from there, they are just small?
Correct?
 
Okay. The Scaling will have reset
Just find your objects, you can highlight them all as before
Set them to 1
You've gave them a new parent, and so the scaling is relative to said parent
 
ok they are back
although they are different
 
In what way?
 
11:18 AM
Okay, this is also fine
So the white images
If you click on one of them
You'll see that they won't have an image in the new Image Script
It'll say, Sprite (None)
You'll need to assign that to the corresponding images
 
some of them still have a sprite attached
 
You're looking at the wrong part
You're still looking under sprite renderer
But this is now under Image, Source Image, Sprite
 
ooh
ok yeah that worked
 
Yeah, you can probably disable the Sprite Renderer for now (It shouldn't be needed anymore but we can keep it for easy undo-ing)
But keep the Image enabled
Now, if you don't want your images to be clickable, or blocking of elements, make sure to disable "Raycast Target"
This should only be enabled for buttons, or elements that you want to register an interaction
 
ok, i disabled it for all of them
how can i show this ingame now ?
 
11:24 AM
Okay, last thing you should need to do for your initial conversion set-up is go to the elements you attached the button script to
And make sure that OnClick, they point to the method you have written in your code
i.e. If I wanted a play button
I would go to that button, go down to onclick, click on the plus icon, set the object to the object that contains my script with the action, and then select the method I want e.g. PlayGameFunction()
 
so i would select a script that is set to run on click ?
 
Yeah, that's right
Because in reality
Say you had a play button, and it was linked to a script that started the game, either by starting it in the same scene, or changing scene
Well, then in code you could also detect a key press, and then perform the same function
That way your code is clean, and not repeating
 
another question, when i add a sprite to my the button objects they get distorted. prntscr.com/mujs1y
 
It's probably a sizing issue
I.e. your button is bigger than you image and it's being stretch, i.e. that fill center could be an issue, try disabling that
By the way, while I'm happy help, here will help you also
Should you wish to do more research on the matter
 
11:38 AM
So, all good?
 
im still a little confused as how to display parts of the canvas
im checking the docs
 
I'm still here just now if you have another question
 
how do i place the ui to show on the screen ?
since its very small at the moment do i just scale it up ?
 
In theory, yeah
Can you send another screenshot?
 
the little white dot there is the gui
 
11:46 AM
The GUI? All of it is a GUI.
Why are some elements of the GUI large and others are small?
Do the smaller ones differ to the larger ones in any way?
 
i only tried this on some parts of the UI, the large parts you see havent been altered
the small dota the arrow is pointing to is the one on the canvas
 
Okay
So quite simply this is just a scaling issue, essentially your elements on your camera are on a different scale to your other elements
So if your other elements are massive in comparison, this will make them look huge
You need to alter all your UI elements as provided above
And then simply ensure your plane distance is set to somewhere between -1 and 1 (I forget which is best)
 
ok, thanks ! i will try and get that working
thanks again for the help :)
 
No bother at all man, good luck with your game - Feel free to follow me on Twitter @DalriadaConnor if you ever need more help or want to play one of my games
 
Will do ! :)
 

last day (15 days later) »