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 meenjedat · Apr 24, 2018 at 01:39 PM · lightingscript.colorlightcolor change

Why change the light color so fast?

Under script is my question.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class LightColorChange : MonoBehaviour {

 private Color kleuR;
 public GameObject dirLight;
 public float takeColorTime = 30;


 void Update () {
     kleuR =Color.Lerp(Color.red, Color.blue , takeColorTime * Time.deltaTime);    
 }

 void FixedUpdate() {
     dirLight.GetComponent<Light> ().color = kleuR ;

 }

}

why is my color chaning so fast and how an i fix it?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Priyanka-Rajwanshi · Apr 24, 2018 at 02:24 PM

@meenjedat Color.Lerp has the third parameter that interpolates betewen 0 and 1 and you are giving it a large value. What you can do is that take a variable and increment it in Update with Time.deltaTime and make takeColorTime value to be small.

   float interval = 0f;
   void Update () {
     interval += Time.deltaTime;
     kleuR =Color.Lerp(Color.red, Color.blue , takeColorTime*interval);    
    }
Comment
Add comment · Show 3 · 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 TreyH · Apr 24, 2018 at 02:34 PM 1
Share

edit: didn't see this answer. $$anonymous$$oving $$anonymous$$e to comment.

@meenjedat : Unless you're writing a script that cleverly changes your light based on how long frame calculations take, this isn't going to be what you want.

Here, you are always starting between Red and Blue -- there will not be any transition at all because you aren't keeping track of intermediate steps along your supposed transition.

Your time multiple also looks very high for lerp. Is this what you meant to do?

 private float colorTransition$$anonymous$$ultiple = 1;
 private float colorTransitionProgress = 0;
 
  void Update () {
      this.colorTransitionProgress  += Time.deltaTime * this.colorTransition$$anonymous$$ultiple ;
      kleuR =Color.Lerp(Color.red, Color.blue , this.colorTransitionProgress);    
  }
  void FixedUpdate() {
      dirLight.GetComponent<Light> ().color = kleuR ;
  }

avatar image Zwerruh · Apr 24, 2018 at 06:13 PM 0
Share

TreyH your method is working, Thanks. But it is still fast not a slow wa to let it change slowly color???

avatar image TreyH Zwerruh · Apr 24, 2018 at 06:16 PM 1
Share

Reduce your multiple:

  private float colorTransition$$anonymous$$ultiple = 0.1f;


If you are this new to C#, you may want to read up on some guides before continuing with Unity.

avatar image
0

Answer by Zwerruh · Apr 24, 2018 at 01:56 PM

Mayby use an other void? not sure.

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

114 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

Related Questions

How to change the color from code 1 Answer

Light Looks Weird 2 Answers

Changing light color back and forth 1 Answer

Change fade distance of shadows on pointlight through script in HDPR 0 Answers

Get "on screen" color of a texture to use in a legend 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