Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by babji3 · Jun 22, 2015 at 10:51 AM · shadermaterialcolorscriptingbasics

How to apply two colors to the object?

Hi all, I want to apply two colors to the cube ,half is red and half is blue. I want to do through the script or material or shader . I dont want to use textures. How i can do this ? Thanks.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Andy.... · Jun 22, 2015 at 03:43 PM

At first I can imagine 2 simple answers:

  • If you're using Unity's cube, put 2 of them side by side and change their colors individually

  • By using any modeling program, it's kinda easy to assign 2 materials to the same model, either by creating a few more vertices and changing their face materials, or by UV Mapping, which would probably lead you to work with "Texture mapping", not necessarily with real texture, just colors.

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 babji3 · Jun 23, 2015 at 05:29 AM 0
Share

First Option i don't need, bcoz i want apply colors only one object.

Is their any option to apply gradient colors to the object ,am using unity cube itself. Thanks

avatar image
0

Answer by Cherno · Jun 23, 2015 at 08:54 AM

You can use the Mesh class to change the cube mesh' vertex colors, and use a shader that supports vertex colors with it. This will automatically give you a smooth gradient between vertices of different color. To find out which vertices are where on the cube, you have to either use the trial and error approach, or use a simple function that displays the vertex number closest to the mouse cursor, like this one I wrote:

 public void GetVertexIndices() {
         Ray mouseRay = Camera.main.ScreenPointToRay (Input.mousePosition);
         RaycastHit hit;
         
         if(Physics.Raycast(mouseRay, out hit, Mathf.Infinity) == true) {
 
             if(hit.collider.gameObject.GetComponent<MeshFilter>() == null) {
                 Debug.Log("Hit object has no MeshFilter!");
                 return;
             }
 
             Mesh mesh = hit.collider.gameObject.GetComponent<MeshFilter>().mesh;
 
             Vector3[] vertices = mesh.vertices;
             int[] triangles = mesh.triangles;
             int vertexIndex0 = triangles[hit.triangleIndex * 3 + 0];
             int vertexIndex1 = triangles[hit.triangleIndex * 3 + 1];
             int vertexIndex2 = triangles[hit.triangleIndex * 3 + 2];
             Debug.Log("Indices for triangleIndex " + hit.triangleIndex + ": " + vertexIndex0 + "," + vertexIndex1 + "," + vertexIndex2);
             //Debug.Log("Vertex Positions: " + vertices[vertexIndex0] + "," + vertices[vertexIndex1] + "," + vertices[vertexIndex2]);
         }
     }


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 babji3 · Jun 23, 2015 at 09:26 AM 0
Share

Nice code , to show the vertex colors. Thanks.

For my issue i have to use $$anonymous$$aterial which is i created in maya ,it has two colors in one material.

In unity it is some difficult to do Half half colors.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

Materials are colored differently on rotated objects 1 Answer

UI Triangle Color picker 0 Answers

Find HDRP Lit Shader 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