Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 astaude · Jul 15, 2015 at 08:44 PM · timelighttimertime.time

Changing light intensity over time via mathf.lerp

Hi guys, sorry to bother. I really hope this is not too stupid, but I don't manage to get it right. So, what I want to do: if [Event] change the intensity of a point light from 0.01 to 1.5 over x seconds under a certain condition.

My Code:

 public class LightWall : MonoBehaviour {
 
 //    public float timer = 10.0f;
     public Light lt;
 
 
 
     // Use this for initialization
     void Start () 
     {
         lt = GetComponent<Light>();
     }
     
     // Update is called once per frame
     void Update () 
     {
 //        FIRST METHOD THAT DID NOT WORK
 //        timer -= Time.deltaTime;
 //        if (timer <= 0)
 //            LightIntensity ();
 
 //        ANOTHER TRY VIA PUBLIC STATIC BOOL
 //        if (outer_fadein.fadeBegin == true)
             LightIntensity ();
     }
 
     void LightIntensity ()
     {
         lt.intensity = Mathf.Lerp (0.01f , 1.5f , Time.time/5);
         Debug.Log ("LightIntensity =" + lt.intensity + Time.time);
     }
 }

The Problem: If I simply call the function in Update, it will increase the light perfectly fine from 0.01 to 1.5. But I only want this to happen after 10 seconds, or better, after fadebegin is set to true. When I try it with one of the two conditions, the light intensity apruptly strikes in instead of beginning at 0.01. Don't know if it's valuable info, but: outer_fadein.fadeBegin will be set to true after 10.00 seconds.

Thanks for the help, I really appreciate!

Cheers!

EDIT: I think the problem is Time.time in

 lt.intensity = Mathf.Lerp (0.01f , 1.5f , Time.time/5);

Since Time.time (which is in my understanding global time since app started) is not 0 when fadeBegin is set to true, intensity will not begin at 0.01f, correct?

How do I solve this? I definetly want this fade to be controlled over a time based value and not being dependant on framerates.

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 OctoMan · Jul 15, 2015 at 10:27 PM 0
Share
 light.intensity = $$anonymous$$athf.Lerp(light.intensity, targetIntensity, fadeSpeed * Time.deltaTime);

just a copy from unity staff, but this might help.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hnm938 · Jul 26, 2019 at 09:08 PM

I think I might be a little too late to help but for anyone that still is looking at this for help like I was, you were right about Time.time being wrong this would be how you fix it.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LightFlicker : MonoBehaviour
 {
     public float maxRange = 11;
     public float minRange = 6;
     public float flickerSpeed = 0.5f;
 
     private Light lightSource;
 
     public void Start()
     {
         lightSource = GetComponent<Light>();
     }
 
     public void Update()
     {
         lightSource.intensity = Mathf.Lerp(minRange, maxRange, Mathf.PingPong(Time.time, flickerSpeed));
     }
 }

I used this for my campfire flicker script, for something like fire setting the maxRange to 11 and the minRange to 6 with a speed of 0.5 is pretty good.

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
avatar image
0

Answer by astaude · Jul 15, 2015 at 10:54 PM

EDITED in first Post

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Stop and Resume Timer 0 Answers

How to reset Time.time ? 1 Answer

Help with time.time when new scene starts. 1 Answer

Why Won't This Message Log Into My Console? 1 Answer

Time based scoring 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