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 kbresciani117 · Jan 08, 2015 at 01:47 AM · randomcolorcolors

Random Color

Hi I am trying to change the color randomly by calling a function but I can't seem to figure out how to even do it. I am new to Developing so I don't know much of anything but if you do help me please explain how you are doing for I can understand and learn :)

function BallColor ()

{

var Color1 : int;

var Color2 : int;

var Color3 : int;

var Color4 : int;

Color1 = Random.value (201, 250);

Color2 = Random.value (201, 250);

Color3 = Random.value (201, 250);

Color4 = Random.value (201, 250);

gameObject.renderer.material.color.(Color1,Color2,Color3,Color4);

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AlucardJay · Jan 08, 2015 at 01:56 AM

http://docs.unity3d.com/ScriptReference/Color.html

Each color component is a floating point value with a range from 0 to 1.

 Color1 = Random.value (0f, 1f);

please format your code

Comment
Add comment · Show 13 · 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 kbresciani117 · Jan 15, 2015 at 03:56 PM 1
Share

I'm trying this but it isn't working.

 function BallColor ()
 
 {
     var Color1 : float;
     var Color2 : float;
     var Color3 : float;
     Color1 = Random.value(0f, 1f)
     Color2 = Random.value(0f, 1f)
     Color3 = Random.value(0f, 1f)
 
     gameObject.renderer.material.color = Color(Color1,Color2,Color3);
 
 }

avatar image AlucardJay · Jan 16, 2015 at 02:57 AM 0
Share

but it isn't working really doesn't give any information. Is it an error? What is the message in the console? In your above code you are missing the ; at the end of the Color lines.

avatar image Cherno · Jan 16, 2015 at 03:09 AM 1
Share

Not only that the ; are missing, but a color consists of four 0-1 values: Red Green Blue Alpha (Transparency, used by Transparent Diffuse shaders for example).

Your color is missing the alpha component, so it has to be

 gameObject.renderer.material.color = Color(Color1,Color2,Color3, 1);

Edit: Color does have a rgb constructor. Thanks to alucardj for the notice.

avatar image AlucardJay · Jan 16, 2015 at 03:32 AM 0
Share

Color does have a constructor for r g b values, and assumes a=1 :)

avatar image Cherno · Jan 16, 2015 at 11:45 AM 0
Share

In that case, I bow to your superior knowledge and will edit out my earlier comment. Thanks :)

Show more comments

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

[Resolved] Game view displays the wrong colors? 1 Answer

i'm trying to code a premise, if 3 objects are the same color then it will destroy the wall 1 Answer

Switch between random colors 4 Answers

Using predefined colors vs defining new colors 1 Answer

How do I randomly create 2 objects, each with a different shape and color? 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