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

Scripting Problems! I'd love some help!

Discussion in 'Getting Started' started by EdenInc, Apr 14, 2016.

  1. EdenInc

    EdenInc

    Joined:
    Apr 13, 2016
    Posts:
    15
    Hey! I'm new to the whole scripting scene but it seems very intuitive to me. However, I seem to be having a problem. I've tried following several different tutorials on how to script different things and the coding itself seems to be doing fine, but the variables never show in the actual Script area in the inspector.
    The below example is very basic.
    This particular example code is in javascript, but the same problem occurs to me in C#. After adding this code to the script, I should be looking at something like this:


    (from a youtube video)

    Instead, it simply looks like this:


    I'd love to get past this problem. There could be several reasons I'm sure, but I can't think one up other than the simple reinstall all the software trick. Not sure if it'll work though. I'm writing this before trying that. I'm assuming it's another problem entirely. The code I've used is found below and is the EXACT same as the youtube video I've been watching to learn it.

    Code (Javascript):
    1.  
    2. #pragma strict
    3.  
    4. var moveUp : keyCode;
    5. var moveDown : KeyCode;
    6.  
    7. var speed : float = 10;
    8.  
    9. function Update ()
    10. {
    11.    if (Input.GetKey(moveUp))
    12.    {
    13.    
    14.    }
    15.    else if (Input.GetKey(moveDown))
    16.    {
    17.    
    18.    }
    19.    else
    20.    {
    21.    
    22.    }
    23. }
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    I don't know about JavaScript, but in C# be sure your variables are declared public.

    Also, note that "KeyCode" and "keyCode" are not the same thing... the latter one is wrong. This makes me suspect that your script isn't even compiling, and you haven't noticed. Before a script compiles, it won't show any changes (such as public variables) in the inspector, so that's probably it.

    Make sure the Console is always visible in your layout, and actually look at it. You'll find the compiler errors there.
     
    jhocking likes this.
  3. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,029
    Just ran a quick script in Unity and it seems to be defaulting to public when not specified.

    This. Mono Develop isn't reporting an error, but Unity itself definitely shows one in the console. Yet another reason why I dislike using a language other than C#. The IDEs will actually pick up on mistakes you've made in the code with C#.
     
    Last edited: Apr 14, 2016
    JoeStrout likes this.