0
\$\begingroup\$

I'm making a platformer game and I need a texture to be only on the top face of a cube and in the centre. Can I do this without scripts or do I need scripts? Also, my texture is transparent and I need it to have a white background, like this: enter image description here

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Do this with a decal. Make the cube white, then create a quad with your top face texture on it and place it on top like a sticker. (Leave a tiny gap to ensure they're rendered in the right order with limited depth buffer precision).

You can parent the quad to the cube, and make a prefab of the pair, so that they're easy to place and move around as a single unit.

If you want to avoid having two objects / draw calls, you'll need to make your own cube mesh with a custom UV unwrap. You'd set the texture coordinates of your custom cube so that the top face samples from the middle of your texture where the design is, and the other faces sample from the edges of the texture so they don't touch the design.

\$\endgroup\$
4
  • \$\begingroup\$ Can I do it without HDRP because everything seems to break when I try. \$\endgroup\$ Commented Jan 22, 2023 at 18:42
  • \$\begingroup\$ Nothing in this answer suggests you would need HDRP. What specific symptoms of "break" are you observing? \$\endgroup\$
    – DMGregory
    Commented Jan 22, 2023 at 18:44
  • \$\begingroup\$ I need to add HDRP to use decals and everything turns pink when I add it. \$\endgroup\$ Commented Jan 22, 2023 at 18:46
  • \$\begingroup\$ Don't use HDRP. Just because HDRP has a feature called "decals" does not mean that's what you have to use. The word decal just means a sticker - overlaying one image/texture on another object, which is a generic description of what you're trying to do. Follow the text instructions of the answer: 1. Make the cube white. 2. Create a quad with your texture one it. 3. Place the quad slightly above the top face of the cube. These are instructions you can follow in any version of Unity, without HDRP. \$\endgroup\$
    – DMGregory
    Commented Jan 22, 2023 at 18:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .