- Home /
The question is answered, right answer was accepted
Where i use Getcomponent() here in this script
#pragma strict
public var lighting:float = 1;
public var lightPower:Light;
public var flashFlg:boolean = false;
public var flashTimer:float = 0.3;
function Start () {
lightPower = this.light;
if( flashFlg ){
lightPower.enabled = false;
yield WaitForSeconds( flashTimer );
lightPower.enabled = true;
}
}
function Update () {
if( lightPower.intensity > 0 && lightPower.enabled)lightPower.intensity -= lighting * Time.deltaTime;
}
Hi I am a dunmer with some knowledge in $$anonymous$$agic "Destruction" field! I can answer that :p
What I can tell is you don't want to use Getcomponent() in update because it is relatively slow. You can use it in Start() function though.
that's it. Thanks @Hellium well 'light' was defined in unity so i thought you might be know . But that's ok , this works , Just need to specify game object .
Don't forget to mark your question as resolved by clicking on the check mark of the post which solved your problem ! ;)
Answer by Hellium · Jun 16, 2015 at 12:17 PM
You will have to be more explicit if you want an answer, nobody here is a wizard ! ;)
What does lightPower = this.light; mean ?
I guess it's here where you have to put the lightPower = gameObject.GetComponent(Light)
Why don't you put your light from the inspector ?
Answer by Calum1015 · Jun 16, 2015 at 02:15 PM
You need to be more specific, so this is a wild guess, but maybe this is what you're looking for:` #pragma strict public var lighting:float = 1; public var lightPower:Light; public var flashFlg:boolean = false; public var flashTimer:float = 0.3;
function Start () { lightPower = this.light; lightPower.GetComponent(); //This allows you a bit more freedom with changing you're light values
if( flashFlg ){
lightPower.enabled = false;
yield WaitForSeconds( flashTimer );
lightPower.enabled = true;
}
}
function Update () {
if( lightPower.intensity > 0 && lightPower.enabled)lightPower.intensity -= lighting * Time.deltaTime;
}` Hope this helped, and if not leave a comment explaining exactly what you need where.
That's good but without arguments it gave me this error - Assets/Particle/$$anonymous$$Y_magicEffectsFree/Script/Lighting.js(9,32): BCE0164: Cannot infer generic arguments for method 'UnityEngine.Component.GetComponent.()'. Provide stronger type information through arguments, or explicitly state the generic arguments.
with argument it gaves me - Assets/Particle/$$anonymous$$Y_magicEffectsFree/Script/Lighting.js(8,26): BCE0144: 'UnityEngine.Component.light' is obsolete. Property light has been deprecated. Use GetComponent() ins$$anonymous$$d. (UnityUpgradable)
with this code - #pragma strict public var lighting:float = 1; public var lightPower:Light; public var flashFlg:boolean = false; public var flashTimer:float = 0.3; function Start () { lightPower =this.light; lightPower.GetComponent(Light); if( flashFlg ){ lightPower.enabled = false; yield WaitForSeconds( flashTimer ); lightPower.enabled = true; } } function Update () { if( lightPower.intensity > 0 && lightPower.enabled)lightPower.intensity -= lighting * Time.deltaTime; }
Hellium code works . thanks for your answer too thumbs up! .
Follow this Question
Related Questions
RealTime Trees Shadows that are instantiated at Runtime(By code)...! 0 Answers
How to avoid load LobbyScene in clients after host quit in lobby 0 Answers
Shader? Light magnifying wall?? 1 Answer
Has my project's data corrupted? Script keeps returning null but 20 minutes ago it wasn't? 1 Answer
How to change animation speed in Unity 5 0 Answers