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 NinjaRubberBand · Feb 18, 2014 at 04:20 PM · arraycolorlight

Can not use more variables in array?

I have this script: #pragma strict

     var duration : float = 1.0;
     
     var color0 : Color = Color.green;
     var color1 : Color = Color.yellow;
     var color2 : Color = Color.blue;
     var color3 : Color = Color.white;
     var color4 : Color = Color.red;
     
     function Update () {
         
         var t : float = Mathf.PingPong (Time.time, duration) / duration;
         light.color = Color.Lerp (color0, color1, t);
     }

In the last line where it says (color0,color1,t) i can't add more of my variable colors to that line. Can someone help me fix it, and tell me why it is like that?

Comment
Add comment · Show 2
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 robertbu · Feb 18, 2014 at 04:22 PM 0
Share

Lerp() only takes two parameters. It linearly interpolates between two values. In order to get an answer, you need to define what you want to happen. If you are trying to fade between color0 to color1, then from color1 to color2, then color2 to color3, and so on, you need to write code to explicitly move from one color pair to the next...and your colors would be better in an array.

avatar image NinjaRubberBand · Feb 18, 2014 at 04:31 PM 0
Share

What you explained is what i want. But sadly i did not write this script. I do hvae 2 months experience in javascripting, but i couldt find this out so i checked it out on the web. If you could give a example that would be great.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AnXgotta · Feb 18, 2014 at 04:42 PM

Try to think about it like this...

You need to Lerp from one color to the next. After that is done, you need to put the color you just changed to in first parameter for Lerp and bring in the next color to change to.

Try using the colors in an array.

 light.color = Color.Lerp(myColorArray[i], myColorArray[i+1], t);

 if(light.color == myColorArray[i+1]){
     if(i >= myColorArray.Length - 2){
         i = 0;
     } else {
         i++;
     }
 }

This will change from one color to the next until the colors have gone through. Then it will restart. If you have an odd number of colors the last one will be skipped.

This should point you in the right direction.

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

19 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

Related Questions

Assigning GUITexture through Javascript 1 Answer

Popular Color/Light Bleeding Effect 0 Answers

Why change the light color so fast? 2 Answers

How to count red colored tiles on my floor? 1 Answer

How do I set the color of a light with a script? 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