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 ImPvEspec · Dec 02, 2012 at 05:22 AM · lightintensitydim

How can I dim light over time?

For a uni brief we have an exploration based game and i want to represent the vehicles fuel/energy, perhaps via a light that dims the longer the player has been out and about. Cant use guitextures, so a literal fuel bar is out of the question, this light dimming thing was best i came up with, and i've looked and not finding much.

Im guessings it's got something to do with get.component, and the intensity of the light. any one able to help me out, or atleast point me in the right direction.

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 DavidDebnar · Dec 02, 2012 at 07:29 AM 0
Share

You could make GUI without GUITextures too. I know this isn't the proper answer, but you can just make a second camera to render on top of the main camera, set it to Ortho, set Clear to none and put some planes with texture infront of it. For some game it's out of question to use 2 cameras, but this is just an idea.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Avaista · Dec 02, 2012 at 05:53 AM

Here is a quick way to do it, it will fade from awakening.

 public class GasMeter
 {
   public Light lightToDim = null;    
   public float maxTime = 30; //30 seconds

   private float mEndTime = 0;
   private float mStartTime = 0;

   private void Awake()
   {
     mStartTime = Time.time;
     mEndTime= mStartTime + maxTime;
   }

   private void Update()
   {
     if(lightToDim)
       lightToDim.intensity = Mathf.InverseLerp(mStartTime, mEndTime, Time.time);
   }
     
 }
Comment
Add comment · Show 6 · 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 ImPvEspec · Dec 02, 2012 at 09:33 AM 0
Share

what are chances of a unity java script tranlastion (sorry i tried to translate my self but all i've even looked at so far is the standard unitys version of javascript

avatar image DavidDebnar · Dec 02, 2012 at 09:37 AM 0
Share

$$anonymous$$Reed's answer converted to javascript. I'm not sure if it works or not, but here it is. Just create a new .js file and paste this in:

 var lightToDim : Light;    
 var maxTime : float = 30; //30 seconds
 
 private var mEndTime : float = 0;
 private var mStartTime : float = 0;
 
 function Awake()
 {
   mStartTime = Time.time;
   mEndTime= mStartTime + maxTime;
 }
 
 function Update()
 {
   if(lightToDim)
     lightToDim.intensity = $$anonymous$$athf.InverseLerp(mStartTime, mEndTime, Time.time);
 }
avatar image fafase · Dec 02, 2012 at 11:05 AM 0
Share

you don't really need all those functions that will only slows down the whole thing.

 function Update(){
   if(lightToDim.intensity >= 0)
     lightToDim.intensity -= Time.delaTime*smoothValue;
 }

That is it. smoothValue allows you to control how long it takes to get light to 0.

If you remove smoothValue, your light will dim in 1s.

avatar image fafase · Dec 02, 2012 at 12:37 PM 0
Share

Did you declare smooothValue?

avatar image fafase · Dec 02, 2012 at 01:47 PM 0
Share

What did you use in the end?

Show more comments
avatar image
0

Answer by PaulBrasfield · Dec 02, 2012 at 07:23 AM

You can just set a timer and have check to see if time elapsed is equal to a set int.

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

14 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

Related Questions

Changing a bunch of lights intensity 2 Answers

How to turn on a light, then off with the same button. 1 Answer

Combinning light shading and slider? 1 Answer

light.intensity is obsolete 1 Answer

Light intensity null reference 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