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

Help with Simulation Game-Teach Mechanism

Discussion in 'Scripting' started by jammachiq, Sep 26, 2014.

  1. jammachiq

    jammachiq

    Joined:
    Aug 30, 2013
    Posts:
    3
    So, I am currently making a simulation game for a college assignment. The game is similar to Tamagotchi, except that I want to have a Teach mechanism that works a bit like Experience. The user interaction is entirely GUI button based and I want it so that when the user presses the Feed button then presses the Teach button, the Creature, that the user is feeding, will earn a a point in FeedTeachSelf (Feeding it self) Then as the Feed TeachSelf levels up so to speak, the Creatures odds of feeding it self at some point through out the day increases.

    Bottom line is. I need help turning this line:
    When someone presses button 1 (Feed for example) and then (afterwards) presses button 2 (Teach) then button 2 (FeedTeachSelf)increments in value.

    Thanks for any help!!!
     
  2. Krysalgir

    Krysalgir

    Joined:
    Aug 30, 2010
    Posts:
    95
    You can have something like that.
    the (m_hasPressedFeed?:"FeedTeachSelf":Teach") if only to change the text displayed depending on the m_hasPressedFeed bool value, don't be afraid :)

    Code (csharp):
    1.  
    2. int m_feedTeachSelfCount = 0;
    3. bool m_hasPressedFeed = false;
    4. OnGUI() {
    5.     if(GUI.Button(yourRect, "Feed))
    6.        m_hasPressedFeed = true;
    7.  
    8.    if(GUI.Button(yourRect, (m_hasPressedFeed?:"FeedTeachSelf":Teach"))) {
    9.         if(m_hasPressedFeed)
    10.             m_feedTeachSelfCount++;
    11.  
    12.         m_hasPressedFeed = false;
    13.     }
    14. }
     
  3. jammachiq

    jammachiq

    Joined:
    Aug 30, 2013
    Posts:
    3
    Oh wow I feel so derpy for completely forgetting about bools xD well im gonna try this out in the Event Manager I have going for the GUIs and ClickActions.

    Thanks so much!! :D
     
  4. Krysalgir

    Krysalgir

    Joined:
    Aug 30, 2010
    Posts:
    95
    bool is love, bool is life