In a way the game is physics based, the actual board has blocks, that will have rigidbody2d and I will do some things to them.
I don’t really get how I place gameobjects on top of the UI with the right size and position.
For example let’s say I have an image of the game minus the board. The UI stuff is extremely large in comparison to gameobjects, I have a background image for my game and if I put it in my game as a sprite ( on a gameobject with a sprite renderer ), how am I supposed to know where to put the UI text etc.? Therefore I used a UI Image for the background, but what about the board? I can also place all the blocks as Images, but I need physics for them, so they have to be gameobjects, but that makes it difficult for me to place them on the right position. I can of course have an UI Image represent a game object ( does that even make sense? ) but then what about physics? If I move the gameobject, the corresponding UI Image will probably don’t move as much…
I hope you get what my problem is, not really sure about the workflow here.
Any help is welcome and appreciated!
Ok, fist off I wouldn’t mix UI versus sprite rendering if you can avoid it. UI elements should be placed on a UI canvas as UI components. 2D Sprite elements should interact with 2D sprite GO’s.
Looking at the image, you could go entirely 2D, or UI or a mix (using each where it is relevant)
My recommendation would be to have the left and right bars as UI with UI images and so on and do the game board in 2D (to get the physics interactions you want. UI Does not play well with physics).
If you need to “Move” elements from the UI Canvas to the 2D renderer, then clone the GO based on it’s intended target (from 2D, instantiate a new UI element parented to the correct canvas and drop iit on UI, From UI, clone a new 2D Prefab and drop it in the 2D system)
Hope that helps.
P.S.
Looking at it, the entire game could be done in UI, but you may have fun getting the Anchors and scaling right
Yeah I also thought mixing sprite rendering and UI is a bad idea. However positioning is a bit weird, since both appear with a total different scale ( UI being much bigger ).
Let’s say I have an image that I use as a background using UI and let’s say that image has an area where the board should be placed. If the board is made out of gameobjects with sprite renderes, then positioning is trial and error, since I can’t really know where they land on the UI stuff.
Is there a way to convert from UI’s position to world space ( I guess )? Then I can set markers on the UI ( like images or something ) and let the gameobjects use that position, so they are positioned correct.
Another question, when I position gameobjects, how do I know they are not out of the screen? Since they are not scaled with the screen size, I guess I work with a fixed resolution?
Yes you can convert from UI (Canvas) space in to world space and vice Versa. There are helper functions on the new RectTransform components to do that.
Either use the “GetWorldCorners” function to translate the values, or simply translate through the camera used by the UI.
As to your other question, it would largely depend on the type of canvas you use. Both of the ScreenSpace canvases take up the entire screen. So any position outside the canvas is outside of the screen.
Worldspace canvases are a bit more tricky, and you need to use the camera view area to determine if something is “off screen” like any other 3D object.