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 /
This question was closed Jun 17, 2015 at 07:19 PM by JeevanjotSingh for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by JeevanjotSingh · Jun 16, 2015 at 12:14 PM · unity 5getcomponentlight

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;
     
 }
Comment
Add comment · Show 3
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 Nerevar · Jun 16, 2015 at 01:21 PM 0
Share

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.

avatar image JeevanjotSingh · Jun 16, 2015 at 05:13 PM 0
Share

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 .

avatar image Hellium · Jun 16, 2015 at 05:21 PM 0
Share

Don't forget to mark your question as resolved by clicking on the check mark of the post which solved your problem ! ;)

2 Replies

  • Sort: 
avatar image
1
Best Answer

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 ?

Comment
Add comment · Show 1 · 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 JeevanjotSingh · Jun 17, 2015 at 07:21 AM 0
Share

Thanks for the working answer .

avatar image
1

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.

Comment
Add comment · Show 1 · 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 JeevanjotSingh · Jun 16, 2015 at 05:10 PM 0
Share

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

Answers Answers and Comments

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

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


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