- Home /
Can I put non-GUI objects into Canvas?
Hi,
I'm creating a 2D jigsaw puzzle game using GUI 4.6. I want to place GUI and non-GUI objects into one Canvas. Non-GUI objects may contain box collider, rigidbody, sprite/mesh render, animations etc.
Is it normal to do so?
If it is logic/convenient in you project to have some objects child of your canvas,I guess it is ok to do so. Be aware you might have some unexpected behaviors with the colliders if they overlap with other UI-elements. $$anonymous$$aybe if you explain a bit more your situation, the community could come with better solutions.
Can you build a 2D game by just using GUI elements? $$anonymous$$y game may not require collision. I think if I put all my objects into Canvas, it's easier to manage and better for scaling. I've just started so I don't have much things to explain.
Answer by DiegoSLTS · May 04, 2015 at 01:17 PM
You can add non-UI objects to a Canvas, but it becomes weird working that way. UI stuff use a Rect Transform, and you can replace the Transform component of an object with a RectTransform, but the values don't make sense any more. A 1x1x1 cube must have a width and height of 1 and then be scaled up, and other anchor options like stretching won't work as expected (they change the width and height, not the scale).
Also, I couldn't add a cube on an Overlay canvas, only in World or Camera space.
You can make a whole game using UI stuff if you're OK with 2D elements. Your jigsaw pieces can be just Image components with a sprite for each piece and you can drag and drop UI stuff with pointer and drag events.
Weird but acceptable. Thanks. I also want to make a book app this way. Sounds easy with Image components.
Your answer
Follow this Question
Related Questions
Canvas Scaler appears to crash my game. 0 Answers
Use Unity UI For 2D Games Or Custom Objects Instead? 2 Answers
How to add sprites to a canvas via scripting 1 Answer
Canvas Scaler - scaleFactor 0 Answers