- Home /
Rescaling a prefab - geometric object with hole in middle
Hi Everyone,
I'm an experienced programmer, but fairly new to Unity. I'm hoping this is an easy one. I've created a prefab called Indicator for my game - it's basically made up of 4 elongated cubes arranged in a frame shape and the idea is that I would be able to slide it back and forth and up and down on various scoreboards. It's working well and I'm able to apply various effects on it when the value is changing that look really good. But where I'm stumped, is when I try to rescale the thing to use elsewhere...
For example, you can see some well behaved indicator prefabs on the Runs Scored and Games Won table. Now, I'm trying to resize it to cover the active players hand of 6 cards over on the left hand side of the screen and I want to make it flash to give a graphic indication that the player has to play a card from his hand.
You can see an instance of a badly rescaled indicator right above the Runs Scored table in this image. As I stretched the prefab out on X, the scaling of the top and bottom components were handled correctly, but the left and right side components were also rescaled making them much fatter. You can actually see the abnormally high scale value in the inspector off to the right. The x dimension of the left side got bumped to 4, but it was originally at 0.15 before I started the stretch.
I can of course, go into the instance by hand and correct the 4 child components of the prefab after the fact, but I'm wondering if there's a way for me to modify the way the editor handles the prefab, so that when I stretch on X, that the left/right components don't get rescaled, and when I stretch on Z that the top and bottom components won't get rescaled?
Would this require a custom editor for the prefab? I've been reading up on OnInspectorUI(), but it seems like a bit of overkill.
Any help appreciated.
=======================================
...and confirmed. I can use a cube or plane, with the frame outline plastered on as an image rather than building a prefab made up of cubes.
The Main Color property of the shader still lets me alter the color of the frame and I;m not locked into what was originally in the image.
Thank you for the advice.
First thought is, this thing has no business being four cubes. It should almost certainly be a UI image with the proper scaling mode to tile a "9-slice" image of a box. Then, positioning this element becomes a matter of setting a single scale to the correct x,y dimensions and placing it in the center of whatever abstract shape it's representing.
If it needs to be cubes, and you really do want exactly what you're asking for, you should write some script which turns a rectangle (or height/width/position, whatever data representation of an intuitive rectangle you like) into scale data for four boundary cubes. It takes a bit of work, but I've done something very similar when I needed resizable boundary colliders to cordon off a physical area.
Fair enough. I thought about doing the frame texture on a plane actually. The reason i didn't is that I want to have effects on it. I need to be able to change colors of the frame and I need it to be able to flash (more of a pulse really....I do a smooth variation between two colors every few seconds) to draw the users attention to whatever it is fra$$anonymous$$g. I thought that if I slapped a frame texture on a single plane or cube, then I wouldn't be able to do those things.
Will experiment a bit with using a image texture.
Sure, you can do those things with an Image just as easily. To be clear, I'm talking about an Image component, which is part of the UI system. It's different from putting a textured material on a quad; superior-to in this situation. You should be using UI elements for anything that is logically an interface element.
https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-image
Your answer
Follow this Question
Related Questions
Change material inside instanced prefab, gameobject.renderer is NULL 1 Answer
How do I scale an object or prefab to a size in Unity units? 1 Answer
How do I scale up a texture along with an ever-expanding underlying body ? 0 Answers
Resize a 3D prefab without affecting scale 2 Answers
OnInspectorGUI with prefabs 2 Answers