- Home /
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.
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.
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);
}
}
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
$$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);
}
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.
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.
Your answer
Follow this Question
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