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 /
avatar image
0
Question by kyriakosstavrou · Nov 22, 2016 at 09:06 AM · percentage

change randomly colors

hello!!! I am trying to make a game... but i have problem... I want my object every 3 sec to change color randomly... 25% red 25% yellow 25% blue 25% green Pls can you help me on that?

Comment
Add comment · Show 5
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 tanoshimi · Nov 22, 2016 at 11:42 AM 0
Share

What code do you have so far?

avatar image roman_sedition · Nov 22, 2016 at 12:12 PM 0
Share

Probably use a self repeating co-routine

e.g

 IEnumerator ChangeColor()
 {
 
 //Your colour changing code
 
 yield return new WaitForSeconds(3);
 StartCoroutine("ChangeColor");
 
 }
avatar image SuleimanAbdulla · Jul 07, 2021 at 11:33 AM 0
Share

i was able to change random color at every 3 seconds using coroutine i hope any one who want to do similar thing will follow this question

public class RandomColorRotine : MonoBehaviour { private bool randomcolor;

     [SerializeField]
     private GameObject _cube;
 
     // Start is called before the first frame update
     void Update()
     {
         if (randomcolor == false)
         {
             StartCoroutine("InvisibleCube");
         }
     }
 
     IEnumerator InvisibleCube()
     {
 
         randomcolor = true;
         _cube.GetComponent<MeshRenderer>().material.color = new Color(Random.value, Random.value, Random.value);
         yield return new WaitForSeconds(3f);
            randomcolor = false;
 
     }
 }



avatar image rage_co SuleimanAbdulla · Jul 07, 2021 at 11:45 AM 0
Share

im sorry i know this is a forum but......clor :insert mememan:.......big sorry couldn't stop myself

avatar image rage_co SuleimanAbdulla · Jul 08, 2021 at 01:57 PM 0
Share

shucks, you edited it

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by romatallinn · Nov 22, 2016 at 12:12 PM

For random colours you can use this:

1) https://docs.unity3d.com/ScriptReference/Random.ColorHSV.html

2) Color color = new Color(Random.Range(0f, 1f),Random.Range(0f, 1f),Random.Range(0f, 1f), 1); // Color


For timeline use this:

 IEnumerator ColorCoroutine()
 {
    while(true)
    {
       // Color change
       yield return new WaitForSeconds(3);
    }
 }

And in Start function, or wherever you want, put StartCoroutine("ColorCoroutine");

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

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

7 People are following this question.

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

Related Questions

Simple Maths Problem (I Suck At Maths) 2 Answers

Calculating percentage in code is reversed? 1 Answer

How do I Adjust The Colour Of My Object By Percentages? 1 Answer

How to find % along path between N points 2 Answers

Simple math? 2 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