Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

why does my script not deactivate

Discussion in 'Scripting' started by dutchkiller2000, Jul 25, 2016.

  1. dutchkiller2000

    dutchkiller2000

    Joined:
    May 13, 2016
    Posts:
    121
    im trying to deactivate a script in another script my script is:

    Code (CSharp):
    1.                 GameObject.Find("player").GetComponent<playerMouseLook>().enabled = false;
    2.  
    i typed player good and mouselook and it trows no errors
     
  2. dutchkiller2000

    dutchkiller2000

    Joined:
    May 13, 2016
    Posts:
    121
  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,738
    just a heads up, but you wont be able to re-enable the script via the same method, since GameObject.Find can not find disabled objects.
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    That doesn't entirely apply here since disabling the component won't turn the GameObject off. That being said - the default override for GetComponent does not return inactive components so you'd have to call GetComponent<playerMouseLook>(true).