Friday, March 21, 2014

2 Week Coding Project - Day 6 : Beginning the Main GUI

Since the rest of the scripts require that I call a specific character from the battlefield, I needed to start working on the out of battle GUI; the menu systems which will allow you to check your player stats and set the player class and role. This is going to take a few days to complete, and is 100% code, pretty much from a single script. This doesn't leave a lot to explain, but I'll take a crack at explaining the work I did today.

I created a list (of 5 for now) of characters that you control in the game. I wanted the player to be able to select a specific character, and then be greeted with a set of menu options, which would allow the player to change the characters class, role, do quests, learn professions, and create objects.

I needed to create a method that would check an integer variable when a specific button is pressed. It was easiest done by making a method called "DisplayCharacterMenu (int cM)" and then made the character buttons simply run the line "DisplayCharacterMenu (#)" where "#" represented the character button they pressed. It was simple from there to create if statements which displayed a new menu based on the integer variable set in DisplayCharacterMenu.

From those variables, I knew the basic integer for the character I wanted the information displayed about. All I had to do was write PlayerPrefs based on those integers and then create Label files which displayed text strings including those preferences.

GUI.Label (left, top, width, height), "Level :" + PlayerPrefs.GetInt("character1Level");

The above script is a general look at how I pulled the information to be displayed. But there was also information that needed to display and set; and I didn't want to do so by duplicating menu's for each character. I created a new integer variable for an extra menu system that would allow me to run a method to set parameters for each character based on which character was selected. This menu then feeds back into the GUI, allowing all of the characters to use the same basic menu's without requiring them to be rewritten for each character.

No comments:

Post a Comment