• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
8
Question by FreeTimeDev · Oct 21, 2010 at 01:35 AM · texture

Texturing a cube; different textures on a face

I'm probably unaware of the proper keywords to search for this, but i know I can't be the first one to ask this:

I want to texture a cube that has the different textures for each of the sides. Can this be done within unity, on a prefab?

Thanks in advance!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · Jul 21, 2018 at 03:04 PM 0
Share

I use a very lazily simple, yet inefficient method. I don't use cubes. Ins$$anonymous$$d, I make a cube of 6 square shaped planes. I then save the 'cube' into a prefab for future use. Then I individually apply such textures. I then

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by jc_lvngstn · Nov 04, 2010 at 01:12 PM

Let's say you have a cube, where each side needs to display a different texture (1-6). In your main script, declare this:

(this is from memory, so bear with me)

public Texture2d[] AllCubeTextures;

public Texture2d TextureAtlas;

public Rect[] AtlasUvs;

Now, when you look at the 2d texture array in the Unity inspector, let's say starting out you have 6 textures, though eventually you may have dozens. Tell the array in the inspector that it has 6 elements assign the appropriate texture to each element in the inspector 1 = your first texture 2 = your second texture, and so on to 6 textures

Now, in back in your mainscript...you need to use Texture2d.Packtextures to pack these into one big texture, the TextureAtlas. If I remember correctly, it's something like this:

AtlasUvs = TextureAtlas.PackTextures(AllCubeTextures);

To generate the cube, just build a mesh "by hand", check out the examples for creating a procedural mesh. I'm some I or someone else can give more information on this if you need it.

So, let's say you have a cube, with each face assigned a texture number. We have a cube where the "front" side needs to show texture number 3, maybe it's a brick texture.

When building the uvs for that cube, you just assign the values from AtlasUvs[3] to the uvs for that face. Sorry if this is not specific enough, I'm not in a position to actually post code for building a cube's faces with uvs, etc. When you actually tell unity to create the mesh, you tell it to use your TextureAtlas texture. All cubes you build would use this same texture atlas, thus everyone really just shares one material.

I hope this is helpful. I think it's a better approach than having a material for each side of the cube, unless you need different shaders for each side of the cube or something.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Skami · Feb 15, 2013 at 05:41 PM 0
Share

I'd love it if you could give some code samples, I've tried to do what you have explained but I don't know what I need to put in the "TextureAtlas" and can't figure out how to apply the AtlasUVs to the uvs of the cube.

avatar image
16

Answer by gaps · Feb 06, 2014 at 09:45 PM

The default cube from Unity does not allow that. But you can make a new cube from 6 quads!

I've made it into a prefab for you, which you can find here. With it, you can apply different textures to each side :)


cube.zip (2.2 kB)
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BHMW · Feb 15, 2014 at 09:33 PM 0
Share

Thanks! Very helpful

avatar image aps502 · Mar 18, 2015 at 05:33 PM 0
Share

Is it possible to set a flag in the inspector to allow us to map to the inside of the cube?

avatar image ftahery93 · Jul 15, 2015 at 06:46 AM 0
Share

Thanks! It was really helpful.

avatar image CrazyChefkoch · Sep 04, 2016 at 02:49 PM 0
Share

Thanks a bunch! I'm struggling that Textures on the Unity Cube are upside down and your cube lets me place the textures in the direction I want and need! :)

avatar image taterbug3000 · Sep 11, 2017 at 07:15 PM 0
Share

really dumb noob question, but once i model my die or cube in Blender, how do I make the 6 quads and export as 6 quads?

Show more comments
avatar image
0
Wiki

Answer by IJM · Oct 21, 2010 at 05:35 AM

You can use FBX model for that.

Most Unity example projects contain FBX models.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FreeTimeDev · Oct 21, 2010 at 07:39 AM 0
Share

How does unity decide what part of the texture goes on what side, is that from the 3d software you used to make the cube in?

Sadly, my game is based around cubes, and because of their simplicity I used Unity's cubes because they're easy, quick and precise. I believe I have to scale your model by 6.5, but even then i'm not sure (there seems to be a seam).

If the above question is yes, I suppose I'll have to rework some levels.

avatar image IJM · Oct 21, 2010 at 07:52 AM 0
Share

By UV mapping. Yes, UV mapping on this cube sucks..but you can make a better cube in just a few $$anonymous$$s with Blender or something else. Or you can use $$anonymous$$esh class to generate a cube from script inside Unity: http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$esh.html

avatar image user-4095 (yahoo) · Oct 26, 2010 at 01:03 PM 0
Share

i cave c4d and tryed to do as $$anonymous$$attew says but it isnt working could u tell me a modeling software that does this?(multiple materials,textures on a mesh)

avatar image BerggreenDK · Nov 21, 2010 at 03:53 AM 0
Share

hmm link is broken again... can we put it somewhere permanent?

avatar image Nicolaj Schweitz · Dec 01, 2010 at 01:56 PM 0
Share

most of the Unity example projects contain FBX files. Replacing the broken link with a link to the Unity Resources.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Importing from maya, textures gone 7 Answers

Render GUI elements to off screen camera 1 Answer

BUG: Editor shows no GameObjects 1 Answer

How to Make a Character Flicker? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges