Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Apr 03, 2016 at 02:00 PM by The Red Wheelbarrow for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by The Red Wheelbarrow · Apr 02, 2016 at 10:24 PM · materialmaterials

Problem comparing materials of GameObjects

Hi! I can't seem to find an answer for my problem over the internet so Im writing here. I have two GameObjects, for instance lets say: gameObject and Cube1. I want to check if, after randomization or after player changes their materials, they have the same color, that is, the same Material. So I do something like this:

 Color1 = Resources.Load("Materials/cube_color_01", typeof(Material)) as Material;
 Color2 = Resources.Load("Materials/cube_color_02", typeof(Material)) as Material;
 
 Cube1 = transform.GetChild(0).gameObject;
 
 //then i run some functions to randomize and assing materials to my gameobjects
 
 //then i check:
 
  if (gameObject.GetComponent<Renderer>().material== Cube1.GetComponent<Renderer>().material)
         {
             Debug.Log("the colors are the same!!");
         }

But it wont work : | I have also tried:

    ( gameObject.GetComponent<Renderer>().name == Cube1.GetComponent<Renderer>().name )

but it also wont work.

Can anybody please help ? :)

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 The Red Wheelbarrow · Apr 03, 2016 at 02:02 PM 0
Share

this works: if (gameObject.GetComponent().material.color== Cube1.GetComponent().material.color)

problem solved

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

57 People are following this question.

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

Related Questions

can i apply an ad on a material 1 Answer

Use a Raycast to get the Material from a shared Mesh (ProBuilder Object) 0 Answers

Fade Transition Between Two Texture 0 Answers

set normal map texture to HDRP/Lit Material 1 Answer

Can I use MaterialPropertyBlock to set properties per material instead of per renderer? 0 Answers


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