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 /
  • Help Room /
avatar image
0
Question by Muhammad_Sannan · Dec 18, 2020 at 11:02 AM · material color

Color Doesn't Change When giving it random value?

  public class SpawnManager : MonoBehaviour
          {
              [SerializeField] private GameObject[] Platforms, SafePlatforms,  DangerPlatforms;
              [SerializeField] private GameObject MainTower;
          
              private MeshRenderer SP_Meshrederer, DP_Meshrederer;
              void Start()
              {
                   //For Spawning
                  /*for (int YPos = 84; YPos > -84; YPos = YPos - 4)
                  {
                      if (YPos % 4 == 0)
                      {
                          int RandomInstantiation = Random.Range(0, 4);
                          Vector3 SpawnPosition = new Vector3(0, YPos, 0), Scale = new Vector3(1, 0.1428571f, 1);
                          GameObject platform = Instantiate(Platforms[RandomInstantiation], 
                                       SpawnPosition, Quaternion.identity);
                          platform.transform.parent = MainTower.transform;
                          platform.transform.localScale = Scale;
                      }
                  }*/
          
                  SafePlatforms = GameObject.FindGameObjectsWithTag("SafePlatform");
                  DangerPlatforms = GameObject.FindGameObjectsWithTag("DangerPlatform");
          
                  Color SP_Color = new Color(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256)),
                        DP_Color = new Color(Random.Range(0, 256), Random.Range(0, 256), Random.Range(0, 256));
          
                  foreach (GameObject platform in SafePlatforms)
                  {
                      platform.GetComponent<Renderer>().material.color = SP_Color;
                  }
          
                  foreach (GameObject platform in DangerPlatforms)
                  {
                      platform.GetComponent<Renderer>().material.color = DP_Color;
                      //DP_Meshrederer.material.color = DP_Color;
                  }
              }
          }

Hi guys i am a beginner and i was stuck here that when i give my material.color a random value through script, the color does not change but when I go to unity inspector open the materials color tab the cursor is on the random color but the material is white and when i write material.color = Color.Red than it works and the object color is changed to red ?? Any help is appriciated!

[1]: /storage/temp/172749-screenshot-2020-12-18-111854.png

screenshot-2020-12-18-111854.png (176.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

152 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 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 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

How can i stop the stretch effect of a material when i add it to an object and then resize it 2 Answers

Why is my plane not changing colors? 1 Answer

Changing a material's colors anywhere else besides the Update function has no effect,Changing Material's color works on Update but not on another method 0 Answers

Fading texture to black is not working correctly 1 Answer

Can i change the color of a ball but only to the spots where it rolls?,Can I Change The Color of A Ball In The Spot Where It Touches The Ground Only? 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