Search Unity

Need help with flashlight script

Discussion in 'Scripting' started by fredr92, Apr 21, 2014.

  1. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292
    Hi !
    Here is the flashlight script im using, made from a youtube tutorial, its working but have some strange behavior . Light is turning on and off, the console say this

    UnityEngine.Component.active' is obsolete. the active property is deprecated on Components. Please use gameObject.active instead. If you meant to enable / disable a single Component use enabled instead.

    The Message is pretty easy too understand i try too use enabled and gameobject.active instead, i get 0 errors but light is not turning on and off. So maybe im missing something, Any help would be appreciated. Im New too Programming but im trying too learn.





    Code (csharp):
    1. var lightOfEpicness : Transform;
    2. var clickAudio : AudioClip;
    3.  
    4. function Start () {
    5.  
    6. }
    7.  
    8. function Update () {
    9.     if(Input.GetKeyUp(KeyCode.T)){
    10.         audio.clip = clickAudio;
    11.         audio.Play();
    12.         if(lightOfEpicness.active == true){
    13.             lightOfEpicness.active = false;
    14.         } else {
    15.             lightOfEpicness.active = true;
    16.         }
    17.     }
    18. }
     
  2. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    lightOfEpicness is a Transform? You don't want a GameObject? or Light? or somethign?
     
  3. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    Change the light to a GameObject, not a Transfrom
     
  4. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292
    Thanks for the fast reply, i will try to remove Transform and use GameObject instead, hopefully it will work !
     
  5. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292


    Here an update on the script, GameObject work well, i also updated the obsolete gameobject.active.
    One more question

    How can i update this line With the new active code? I tried using Set.Active(true) but im probably missing something here, please help, thanks !

    if(lightOfEpicness.active == true){
     
  6. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
  7. fredr92

    fredr92

    Joined:
    Jul 8, 2013
    Posts:
    292
    solved With .activneInHierarchy Works like a charm !