- Home /
What is wrong with my C# script?
I am trying to make a fire, where the light starts to appear as my fire does. I tried to write a code for it, but it simply changed the intensity right when I press play instead of as the fire builds like I want it to.
using UnityEngine;
using System.Collections;
public class LightScriptoid : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update() {
if(gameObject.particleSystem.startDelay == 2.0f){
}
gameObject.renderer.light.intensity = 1.0f;
}
}
Answer by Scrapy_ · Apr 13, 2014 at 05:39 AM
I recently went through the project tutorials, and I think what you want might be there.. http://unity3d.com/learn/tutorials/projects/stealth/alarm-lights
something like this? a lower fadespeed value will cause the light to fade in slower, and high will increase it.
using UnityEngine;
using System.Collections;
public class LightScriptoid : MonoBehaviour {
// Use this for initialization
void Awake ()
{
// When the level starts we want the light to be "off".
light.intensity = 0f;
}
void Start () {
}
// Update is called once per frame
void Update () {
if (gameObject.particleSystem.startDelay == 2){
float fadeSpeed = 0.5f;
gameObject.light.intensity = Mathf.Lerp(light.intensity, 1f, fadeSpeed * Time.deltaTime);
}
}
}
It worked, thanks a lot! I am sort of a noob at unity. Could you explain to me how that worked? I get most of it, but $$anonymous$$athf.Lerp kind of confuses me a bit! Thanks! :D
glad it worked :)
I'm fairly new myself, the guy in the tutorial explains a little, basically it allows you to increase a value kind of like if you were to adjust a slider. so as the time goes by "fadespeed" the number will rise until it reaches what you have set. so like 0.1,0.2,0.3, up until 1.
not sure if I explained that correctly, but that is my understanding.
FireHawk33, please click the Accept this Answer as correct icon next to the Answer to earn Scrapy and yourself some karma
I did so! :D Thank's scrappy and getyour411. Im glad you guys arent like the other people who think noob's questions should be gotten rid of. I dont know where Id be then >.<
Answer by mattyman174 · Apr 13, 2014 at 03:17 AM
if(gameObject.particleSystem.startDelay == 2.0f)
{
gameObject.renderer.light.intensity = 1.0f;
}
I assume this is what you were meaning to do?
In your original code your changing your light intensity outside of the IF statement.
Didnt work. I want it so that when the particle system is at full effect, the light starts up
I tried that, but it still changes the intensity to 1 right when I press play. I want the light to show up when the fire is at its fullest extent.