- Home /
Good way to scale 3D GameObjects in a Canvas (Screen Space - Camera)?
Howdy, I'm tryna make some shop items with the actual items spinning in 3d (in a 2d frame), and then all of the items in a scroll rect. It's all going fine except the canvas isn't affecting the scale of the models (even if I change their transforms to recttransforms). I have seen similar problems solved by rendering the items with another camera into render textures, then showing the render texture with a rawimage, but I want to have like 10 separate shop items there at once . . . If I could just scale the objects in a reliable way, I'd be set.
Any ideas appreciated, thanks
Answer by KillHour · Oct 26, 2015 at 11:59 AM
Render to texture is probably the best way to do this, but if you're dead set against it, you could add something to the existing code that makes the objects rotate to change the scale at the same time.
Something like this should work:
public GameObject[] windowTargets;
public void RotateAndScale(float rotateSpeed, float sizeScale, Rect windowSize) {
float s = Mathf.Min (windowSize.x, windowSize.y);
foreach (int element in windowTargets) {
windowTargets[i].transform.Rotate (0, rotateSpeed * Time.deltaTime, 0);
windowTargets[i].transform.localScale = new Vector3 (sizeScale * s, sizeScale * s, sizeScale * s);
}
windowSize needs to be relative, not absolute pixels, or it's going to be wrong when you change the resolution. Again, render to texture avoids a ton of potential problems with this.
Thanks for the reply. I'm not particularly dead set on not using render textures, I just don't know of a good way to do it. I wanna have at least like 5 different spinning items showing at once, wouldn't that mean I need 5 extra cameras? Anyways thanks for the reply, I'll try it out.
$$anonymous$$aybe I'm being a dummy actually, maybe I should just be using an orthographic world space camera . . .
Your answer
Follow this Question
Related Questions
Move UI object to center of screen while maintaining its parenting 2 Answers
UI not scaling correctly with screen resolution 1 Answer
Editing RectTransform scale 2 Answers
Different Normal vs Debug Mode values in Inspector. RectTransform bug may be? 0 Answers
change/scale child rectTransform with Parent (with video) 0 Answers