Search Unity

Hmm... What the hell is going on?

Discussion in 'Scripting' started by cristo, Dec 16, 2014.

  1. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Can anyone tell me why the Door isn't turning up as a gameObject in the script in the inspector? I'm probably doing something stupid, but I've tried 20 different combinations to make it work and it still resides in this half-dark inaccessible font, (i.e, I can't drag an object from the hierarchy to the inspector).
    The animation is legacy. It plays if I tick play automatically.
    Just can't get the Player to trigger the animation.
     

    Attached Files:

  2. codezeero

    codezeero

    Joined:
    Apr 12, 2014
    Posts:
    24
    you can use Door = this.gameObject as the script is already attached to the GameObject Door .
    try making the Door to public variable and drag and drop the GameObject "Door" to the Script .


    Finally get the animation component using get component function .
    Then play the clip
    Door.GetComponent<Animation>().Play("Take 001");
     
  3. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    You're in Debug Mode Inspector ;

    UnityDebug.jpg

    Select "Normal". And your variable is private, so you can do nothing from the inspector. Set it as public if you want to drag something in.

    Edit: this is kind of stupid to do that if you want to have the current gameObject 'cause you already have a variable named "gameObject" inherited from MonoBehaviour.
     
  4. A.Killingbeck

    A.Killingbeck

    Joined:
    Feb 21, 2014
    Posts:
    483
    It won't show up in the inspector as you're assigning it at runtime. The reason it's shown as inaccessible is it's a private variable and you have the inspector in "Debug" mode. If you change the inspector back to normal mode, you won't see the variable at all.
     
  5. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    many thanks codezero,

    Thanks so much for your help. I thought I understood how to do this, and then tried to quickly do it again and ran into three hours of pain. Probably a common experience in coding. ;)
     
    codezeero likes this.
  6. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
  7. codezeero

    codezeero

    Joined:
    Apr 12, 2014
    Posts:
    24
    Its a good practice I would say, you make mistake and learn from it so you will never re do the mistake again . have a good time coding buddy and remember this community is always here to help you .