I've got a scene for a dynamic menu, where I'm trying to make the camera move between the canvases (menu entities in this case) when a button is pressed. How can I make it move to another canvas space using four canvas corners so the camera's field of view can attach itself to these four corners. P.S. I'me pretty new to Unity, don't be too judgy.
Something like this plan.
Menu Layout
Thanks in advance!
As far I have understood, you can set the Canvas Render Mode to World Space from the inspector.
Then you can position the Canvas position as your wish.
Please see the attached images.
Related
The project is a 2D platformer for Android devices. I created a main menu with animation on one canvas and an options menu with animation on another canvas. My goal is to have a transition between the two when a button is clicked.
Images:
Main Menu, Options Menu, Main Menu On Load
I tried to create a nested canvas with these two other canvases but I get an error on the canvas scaler component - non-root canvases will not be scaled. UI Scale Mode is Scale With Screen Size. The menus dissapears in the bottom left corner, barely visible.
No script yet
I expect to create a script or a controller to switch between these canvases. I saw this video https://www.youtube.com/watch?v=7Z4AuSQtLv0 but there is just one canvas and the UI elements are nested on different panels. Is this possible with canvases?
I suggest you to make 2 different scenes, one for each menu. The best thing about this is modularity and ease of use, you just swap scenes when needed. Keep in mind for the Pause Menu Scene that you must swap to it additively so you don't destroy the game Scene.
Call the animation on each one when menu is swapped (just before swapping scenes):
//Here you play the animation
SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);
If you have placed the game and the menus in the same scene, split them, managing your game with scenes is the way to go.
Source: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html
I am trying to make an animation of a countdown.
I first made a Gameobject, created a canvas for it, and inside that canvas I created a UI Image, attached an image to it, and finally created an animation with that image.
Everything is working fine except the animation is not showing in game scene but only in normal scene, but when I go to that UI Image component and start the game I can see the image changing which means that its not the animation but something else.
Does anyone have an idea of what's going on?
There are several possibilities. Depending on if the image is showing up at all, you can check if your UI image is anchored correctly (four triangle marks) or pivot position is where you want it (circle mark). Depending on how this is done, if you Game window resizes in play-mode with the display set to Free Aspect, your image may move off the visible screen or, in some cases, get crushed which usually shows up as a red X in the editor. I can see this happening if your Game window is set to Maximize on Play.
Did you find out why this was happening? I'm having the same issue here.
I had a canvas with a scroll bar working normally, I needed to set the canvas render mode to "Screen Space - Camera", and now the bar doesn't move anymore.
When you change the Canva's Render Mode from Screen Space - Overlay to Screen Space - Camera, an new slot called Render Camera will appear under the Canvas. Drag your main camera into this slot. That camera will be used to send events to the UI elements.
If you've already done this but the problem is still there, delete the ScrollRect and create a new one. Finally, if the ScrollRect is still not moving, make sure that no other UI object is blocking it.
Maybe a hidden panel or image with 0 alpha... Any UI object that is below the ScrollRect in the Hierarchy tab will block the ScrollRect if on top of it.
EDIT:
Once you drag the main camera to the Render Camera slot, Plane Distance slot will appear. Also make sure that it's not set to 0. Mine is set to 100 as shown in the screenshot above and that should work fine.
There might be multiple reasons why your scrollview doesn't work
I encountered with a similar problem. My canvas had a background image so i had to put a Image element without a sprite and set the alpha to "0" within Content of scrollview.
when your viewport field is not referring to viewport object in scroll rect
Try altering the movement type
I also had this problem due to not having an EventSystem in the scene.
I am trying to make a VR game with google cardboard in unity. However we can not find a way to display score text right in front of the player. However when I add 2D text it is only on one side and therefore on one side of the eye and getting the position right for 2 texts is hard. If I use 3D text and set in front of the players position I think it will go into the wall if a player hits one. Is their any way to display a score on google cardboard / Unity VR.
You can either use native Unity Canvas UI or Googles hack to render OnGUI calls onto a texture.
I would definately recommend Canvas as that is the way Unity is working on their UI features, and it has much better layout capability.
To use canvas, Right click in the hierarchy and add UI->Text. You will automatically get a canvas. The important part is set the canvas to world-space (not screen space overlay). Then drag the canvas game object so it is a child of the Google Cardboard Main head object. Scale it down (like x:0.001,y:0.001,z=0.001) because by default it will be massive. To avoid going through walls position it about 0.5m in front of the camera - within any collider you may have.
there is another approach as well which you can place that canvas under camera make it world space, and then adjust it as you want, after that where ever you look at it will be seen easily ( as suggested by earlier user in answers) as you can see below in picture i placed canvas > Text > under camera which i used for oculus/ google camera
I have to create a sample silver-light page that has some user interactive elements like -
1) A ball and two arrows for left and right directions.
Clicking on any arrow should cause the ball to move in that direction.
2) A drag and drop functionality for some object on the screen.
3) Clicking on a ball should make it rotate.
Please help me as i m new to this area.
Thanks in advance.
You can use the Animations using xaml
If you have the Microsoft Blend then it is very easy to animate
example