Search Unity

Expecting }, found 'static'

Discussion in 'Scripting' started by Ethan8094, Aug 29, 2015.

  1. Ethan8094

    Ethan8094

    Joined:
    Aug 29, 2015
    Posts:
    4
    Expecting }, found 'static' is the error

    static var ammo = 100;
    static var maxAmmo = 100;
    var key : String = "mouse 0";
    var bullet : Rigidbody;
    var speed : float = 1000;

    function Update () {
    if(Input.GetKeyDown(key)){
    if(ammo > 0){
    shoot();
    }
    }
    }

    Please Help.
     
  2. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    Learn proper syntax.
     
  3. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    First of all LaneFox, if you won't help, then go away, noone asked you. Secondly, if you could post the whole error, not just one part of it, it will be easier to help, which line is the error referring to exactly?
     
  4. Ethan8094

    Ethan8094

    Joined:
    Aug 29, 2015
    Posts:
    4
    static var ammo = 100;
     
  5. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,536
    Take a look at that script again.
     
  6. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Is this the whole code, or just a part of it?
     
  7. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Yeah, what's the problem?
     
  8. Ethan8094

    Ethan8094

    Joined:
    Aug 29, 2015
    Posts:
    4
    part of it
     
  9. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Could you post the whole code?
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's nothing wrong with what was posted (aside from not using code tags).

    Post the whole thing, use code tags, and proper formatting.

    --Eric
     
    gorbit99 likes this.
  11. Ethan8094

    Ethan8094

    Joined:
    Aug 29, 2015
    Posts:
    4
    Nevermind, I got it fixed, one of the lines of code before that was not closed properly
     
    LaneFox likes this.
  12. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Yeah, I expected that, it's not the best thing to format code like variables - function - more variables - function - etc etc.
    It's easier to understand, if you store every variable at the same place. You could also put some space between two variable group at the beginning and use comments to tag them.
     
    Ethan8094 likes this.