Pookie
Pookie

Reputation: 1279

Canvas scaling for GameObjects in Unity

I have searched online for the problem, and they always result in code. I am trying to do scaling of GameObjects just like I would an Image. Let me explain, here is an Image of me manipulating an image with a canvas:

enter image description here

Now here is an image of my paddle in inspector

enter image description here

The paddle has an image, a ridged body, box collider, etc. But I want the paddle to be able to be scaled like the background image gets scaled. Is there a way I can put the paddle in the canvas so that the box collider, image, etc scales. Any help with this is extremely appreciated.

Upvotes: 0

Views: 1796

Answers (1)

Basile Perrenoud
Basile Perrenoud

Reputation: 4112

No, I don't hink there is a simple solution to your problem, because the elements you want don't necessarily have a width and height that means something in a RectTransform.

For instance, your box collider is a 3D shape (speaking of this, you might want to use a BoxCollider2D) Anyway, Only the Unity UI components react to RectTransforms. Colliders aren't UI elements. All the components you talk about react differently:

  • Image is a 2d ui component with a width and height. It will scale in your canevas

  • BoxCollider isn't a UI element. it won't scale, but you can do it programmatically by copying the values of transform.Rect inside collider.Size. I am pretty sure you can find several examples of that on the internet

  • Paddle is your own component, so of course it will only do what you programmed it to do. I don't see what you mean by "put the paddle in the canvas". Your paddle isn't a graphic element. It doesn't have a width and height. The Image component however will have a width since it is a UI component

Upvotes: 2

Related Questions