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

Hunger Script Problem

Discussion in 'Scripting' started by FennexStudios, Sep 13, 2014.

  1. FennexStudios

    FennexStudios

    Joined:
    Jul 4, 2014
    Posts:
    15
    Hey guys,

    I'm working on a Hunger/Thirst system for my Unity Game. I've created the code to generate GUI buttons to tell the players their current hunger and thirst. Unity says there's compiler errors but won't tell me what they are. Any help would be greatly appreciated.

    #pragmastrict

    var currentHunger : float = 100.0;
    var maxHunger : int = 100.0;

    var currentThirst : float = 100.0;
    var maxThirst : int = 100.0;

    private var barLength = 0.0;

    functionStart ()

    {

    barLength = Screen.width / 8 ;

    }

    functionOnGUI ()

    {

    GUI.Box(newRect( 5, 30, 50 ,23), "Hunger";
    GUI.Box(newRect( 5, 55, 50 ,23), "Thirst";



    GUI.Box(newRect( 55, 30, barLength, 23), currentHunger.ToString("0") + "/" + maxHealth);
    GUI.Box(newRect( 55, 55, barLength, 23), currentThirst.ToString("0") + "/" + maxThirst);

    }
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Please use code tags.

    Note that there's needs to be a whitespace between the keyword function and the name of the function. Also the same with the pragma and strict.
    In the OnGUI function, there're missing several parentheses.

    Unity generally helps alot to sort out errors, the messages can be found in the console and are almost always easy to understand.
     
  3. FennexStudios

    FennexStudios

    Joined:
    Jul 4, 2014
    Posts:
    15
    Thanks Suddoha, I figured it out and now have a working health and thirst system. I'll remember to use code tags the next time.