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