Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Natsu_Firefoc · May 27, 2016 at 04:54 PM · guiif-statementsinheritancevisualstudiocondition

[GUI] Conditional Trigger for Button is flawed

Problem: My finish button in the first code of text wont appear when the conditions are met. What is the flaw in my code? Someone please help.

I have a script in my DisplayCreatePlayerFunctions file:

 using UnityEngine;
 using System.Collections;
 
 public class DisplayCreatePlayerFuntions
 {
     private StatAllocationModule statAllocationModule = new StatAllocationModule();
 
     private int classSelection;
     private string[] classSelectionNames = new string[] { "Human", "Kiriko" };
 
 
     public void DisplayClassSelections()
     {
         //List of toggle buttons and each button will be a different class via selection grid
 
         classSelection = GUI.SelectionGrid(new Rect(50,50,250,300), classSelection, classSelectionNames, 2);
         GUI.Label(new Rect(320, 50, 300, 300), FindClassDescription(classSelection));
         GUI.Label(new Rect(320, 100, 300, 300), FindClassStatValues(classSelection));
         
 
     }
 
     private string FindClassDescription(int classSelection)
     {
         if (classSelection == 0)
         {
             BaseCharacterClass tempClass = new BaseHumanClass();
             return tempClass.CharacterClassDescription;
         }
         else if (classSelection == 1)
         {
             BaseCharacterClass tempClass = new BaseKirikoClass();
             return tempClass.CharacterClassDescription;
         }
         return "WIP";
     }
 
     private string FindClassStatValues(int classSelection)
     {
         if (classSelection == 0)
         {
             BaseCharacterClass tempClass = new BaseHumanClass();
             string tempStats = "Stamina " + tempClass.Stamina + "\n" + "Endurance" + tempClass.Endurance + "\n" + "Agility " + tempClass.Agility + "\n" + "Speed " + tempClass.Speed + "\n" + "Control " + tempClass.Control + "\n" + "Strength " + tempClass.Strength;
             return tempStats;
         }
         else if (classSelection == 1)
         {
             BaseCharacterClass tempClass = new BaseKirikoClass();
             string tempStats = "Stamina " + tempClass.Stamina + "\n" + "Endurance" + tempClass.Endurance + "\n" + "Agility " + tempClass.Agility + "\n" + "Speed " + tempClass.Speed + "\n" + "Control " + tempClass.Control + "\n" + "Strength " + tempClass.Strength;
             return tempStats;
         }
         return "WIP";
     }
 
 
     public void DisplayStatAllocation()
     {
         //A list of stats with a plus to add stats
         statAllocationModule.DisplayStatAllocationModule();
         
     }
 
     public void DisplayFinalSetup()
     {
         //name/gender/add a player desc.
 
     }
 
     private void ChooseClass(int classSelection)
     {
         if (classSelection == 0)
         {
             GameInformation.PlayerClass = new BaseHumanClass();
         }
         else if (classSelection == 1)
         {
             GameInformation.PlayerClass = new BaseKirikoClass();
         }
     }
 
     public void DisplayMainItems()
     {
         GUI.Label(new Rect(Screen.width / 2, 20, 250, 100), "Create New Player");
 
         if (CreateAPlayerGUI.currentState != CreateAPlayerGUI.CreateAPLayerStates.FINALSETUP)
         {
             if (GUI.Button(new Rect(470, 370, 50, 50), "Next"))
             {
                 if (CreateAPlayerGUI.currentState == CreateAPlayerGUI.CreateAPLayerStates.CLASSSELECTION)
                 {
                     ChooseClass(classSelection);
                     CreateAPlayerGUI.currentState = CreateAPlayerGUI.CreateAPLayerStates.STATALLOCATION;
                 }
                 else if (CreateAPlayerGUI.currentState == CreateAPlayerGUI.CreateAPLayerStates.STATALLOCATION)
                 {
                     CreateAPlayerGUI.currentState = CreateAPlayerGUI.CreateAPLayerStates.FINALSETUP;
                 }
                 else if (CreateAPlayerGUI.currentState == CreateAPlayerGUI.CreateAPLayerStates.FINALSETUP)
                 {
                     if (GUI.Button(new Rect(470, 370, 50, 50), "Finish"))
                     {
                         Debug.Log("MAKE FINAL SAVE");
                     }
                 }
             }
         }
 
         if (GUI.Button(new Rect(295, 370, 50, 50), "Back"))
         {
             if (CreateAPlayerGUI.currentState == CreateAPlayerGUI.CreateAPLayerStates.STATALLOCATION)
             {
                 CreateAPlayerGUI.currentState = CreateAPlayerGUI.CreateAPLayerStates.CLASSSELECTION;
             }
             else if (CreateAPlayerGUI.currentState == CreateAPlayerGUI.CreateAPLayerStates.FINALSETUP)
             {
                 CreateAPlayerGUI.currentState = CreateAPlayerGUI.CreateAPLayerStates.STATALLOCATION;
             }
 
         }
     }
 
 }
 

Here is the CreateAPlayerGUI File:

 using UnityEngine;
 using System.Collections;
 
 public class CreateAPlayerGUI : MonoBehaviour {
 
     public enum CreateAPLayerStates
     {
         CLASSSELECTION, //display stat types
         STATALLOCATION, //allocate stats
         FINALSETUP // add name, and gender
 
     }
 
     private DisplayCreatePlayerFuntions displayFunctions = new DisplayCreatePlayerFuntions();
     public static CreateAPLayerStates currentState;
 
     // Use this for initialization
     void Start () {
         currentState = CreateAPLayerStates.CLASSSELECTION;
     
     }
     
     // Update is called once per frame
     void Update ()
     {
         switch(currentState)
         {
             case (CreateAPLayerStates.CLASSSELECTION):
                 break;
             case (CreateAPLayerStates.STATALLOCATION):
                 break;
             case (CreateAPLayerStates.FINALSETUP):
                 break;
         }
     
     }
     void OnGUI()
     {
         displayFunctions.DisplayMainItems();
 
         if (currentState == CreateAPLayerStates.CLASSSELECTION) //
         {
             displayFunctions.DisplayClassSelections();
         }
         if (currentState == CreateAPLayerStates.STATALLOCATION) //
         {
             displayFunctions.DisplayStatAllocation();
         }
         if (currentState == CreateAPLayerStates.FINALSETUP) //
         {
             displayFunctions.DisplayFinalSetup();
         }
     }
 }
 


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

FPS Styled Timer Game: Script for starting a timer on play and stopping the timer when win condition achieved. 1 Answer

Execution order of conditional operators in an if-statement 1 Answer

If statement with multiple conditions 0 Answers

How to use IF in Unity for selection MyScript 1 Answer

Class Inheritance Issue. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges