When I spawn in a UI object my Canvas spawn with the bottom left corner at 0,0 on my scene. I want it to overlay the scene correctly, BUT if I switch hit Render Mode: Camera is does not properly overlay the UI. Is there a fix for this?
You need to change the Canvas Scaler to Scale With Screen Size.
Cheers!
Related
In Unity: How can I draw GUI texture (GUI.DrawTexture) on my 2D application and at the same time have some UI buttons to appear over the drawn GUI and also to be able to interact with these buttons?
Use Unity's LineRenderer and Image or RawImage because GUI.DrawTexture is from IMGUI and should only be used to make Editor plugins or tools.
I tried it but it didn't get what i want from it (LineRenderer is
drawn under all UI elements which is the opposite of GUI.DrawTexture )
The problem is how you setup the Canvas. The default Canvas Render Mode is "Screen Space - Overlay". When the Canvas is set to "Screen Space - Overlay", it will display on top of everything.
Change your Canvas Render Mode to "Screen Space - Camera" then add your main camera to the Canvas' "Render Camera" slot. You can also use "World Space" as Render Mode. LineRenderer should now display on top of the Canvas.
I am new to canvas. I am wondering if I can take a Fabric JS canvas and put it on time of an existing Fabric JS canvas? If so, I would I do this.
Yes, you can do this. Canvas backgrounds are transparent by default, so you are able to overlap them as layers. Use CSS to put the canvas elements exactly on top of each other.
Make sure, when clearing the top canvas, you use clearRect and not fillRect with a background color (even white), as that would remove the transparency and hide the other canvas.
I am trying to use the new 4.6 Unity GUI system to create a bit of UI. I want to make this UI at a resolution of 400x300, then render to a texture which will then be drawn to the screen at a resolution of 800x600 (so double resolution). The problem is this: It doesn't work. The rendering is okay and I can correctly upscale the render texture and have it drawn to the screen, but the UI events aren't received in the correct position, and I can find no way to get around this.
So:
Player resolution is 800x600 Render texture resolution is 400x300
Main camera, called "UI Camera" renders to this texture (at 400x300)
Canvas set to "Screen Space - Camera" pointing at "UI Camera". Under this is a button which is set to stretch to all sides (so fullscreen, 400x300)
A second camera, called "Upscaling Camera".
Another canvas set to "Screen Space - Camera" pointing at "Upscaling Camera".
This canvas has it's GraphicRaycaster component removed. Under this is a RawImage displaying the render texture.
When I play, the UI is correctly rendered to the rendertexture, and then displayed on screen at 2x resolution, filling the screen. What is not working is the events - the button can only be interacted with when the mouse is in the lower-left quarter of the screen.
Conceptually, this makes sense. The button is occupying a space from (0, 0) to (400, 300) (starting at the bottom left of the screen), and now my player's resolution is 800x600, this rectangle only covers the bottom left corner. I get that.
So, with all that said, what can I do to fix this? I can't set the EventCamera on the GraphicRaycaster, so that's out. My next thought was to be somehow fudging the mouse positions. But honestly, I have no clue where to go.
(And in case somebody has a better way of doing this - I'm looking at a game working in 400x300 resolution which needs to be pixel-perfect. If I were to resize all my UI externally, that would mean that in-engine, they are essentially running on a half-pixel grid. Same goes for using the CanvasScaler component.)
Cheers for any help.
I have embedded a Video in HTML5 page over a Canvas.
I want to draw a rectangle with mouse events on the Video and rectangle should not be erased.
Please help me how to do this ..
Thanks..
You can create a new Canvas Element just on top of your Video-Canvas. and Handle your mouse events for that new canvas element. and Make sure that you do not set the background property for your new canvas, this will make it transparent and the Video-Canvas elements content will be visible. Let me know if you do not get it.
I'm trying to get the data from a canvas and set the src attribute of a img element. The problem here is that, the canvas has a background image setted with css, not with canvas methods. Is there any way or method to extract the background image so the toDataURL method could catch it?
Thanks
I guess there is a solid reason why you are not drawing the background image to the canvas itself so I can offer you this solution:
Draw the background-image to a second canvas element positioned below the first canvas.
When you want to take the canvas data and use it create a third canvas (no need to attach it to the DOM or make it visible.
Draw the background canvas onto it and then draw the main canvas on top.
Take the data from the third canvas.
Voila.