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 /
  • Help Room /
avatar image
0
Question by KyleF1997 · Feb 14, 2017 at 03:18 AM · lightingfloatinvokerepeatingincreasedecrease

Decreasing a value over time, called by InvokeRepeating

I'm attempting to create an effect in my game in which two discreet spot lights lower and raise their intensity every so often to give the impression that the player is actually travelling through space.

The method I'm using does work to an extent;

     void Start ()
     {
     InvokeRepeating("LightChange", 5, 30);
     }
 
     void LightChange()
     {
         if (Random.value >= 0.5f)
         {
             dirLight1.intensity -= (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f));
             dirLight2.intensity += (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f));
         }
         else
         {
             dirLight1.intensity += (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f));
             dirLight2.intensity -= (Mathf.Clamp(0.05f * Time.deltaTime, 0.00f, 0.5f));
         }
     }

It works in that the function is called and the value for the light intensity does indeed change, although it only changes for a moment (from .5 to .45) whereas the intended effect is that the values would decrease/increase to their minimum/maximum respectively.

Comment
Add comment · Show 1
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 Pengocat · Feb 14, 2017 at 03:42 AM 0
Share

Do you want a sudden change in intensity like from 0.4 to 0.1 or should it slowly change over time? The code you have here is going to bounce a little bit since Time.deltaTime is the time that has passed since the last frame so it is only going to give a change if the framerate is changing a lot. Perhaps $$anonymous$$athf.PingPong is useful for you.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

gradual ambient light intensity change 2 Answers

increase decrease score on multiples button click problem 0 Answers

C# decreasing float slightly incorrect (0.4999999) 1 Answer

How can I change the value of a Float smoothly? 2 Answers

Disable all lighting? 0 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