Monday, February 28, 2011

Score Screen Finally Finished

I've been busy with teaching and other sundry university service responsibilities, which has taken me away from game development these last few weeks. Thank goodness that I was able to get the majority of development done during Winter Term when I didn't have a teaching load. The final problem I faced was getting the player performance data out of the game and into the score screen. In Unity, when one game scene is unloaded and a new scene is loaded, all assets (including class variables, etc.) associated with the old scene are destroyed. I was able to find a work around to this problem by 1) saving the performance data as player preference data in one scene, and 2) loading these variables in the new scene. Here's the code for it:

In the old scene, once the player completes that last task, his performance data is sent to the system before the new scene is loaded:

PlayerPrefs.SetString("PointsScore", pointsHolder.guiText.text);
PlayerPrefs.SetString("HealthScore", healthHolder.guiText.text);
PlayerPrefs.SetString("MoneyScore", moneyHolder.guiText.text);

Here I'm directly accessing the guiText object where this data is stored and then sending this data as a string object to the player preferences. In the new scene, I use the following code (excerpted) to get the data out of the system and printed to the screen:

public string finalPointScore;
public string finalHealthScore;
public string finalMoneyScore;
public GameObject geld;
public GameObject gesundheit;
public GameObject punkte;

public void Awake()
      Screen.showCursor = true;
      Screen.lockCursor = false;
      finalPointScore = PlayerPrefs.GetString("PointsScore");
      finalHealthScore = PlayerPrefs.GetString("HealthScore");
      finalMoneyScore = PlayerPrefs.GetString("MoneyScore");

      geld = GameObject.Find("GUITextGeld");
      geld.guiText.text = finalMoneyScore;
      geld.gameObject.transform.position = new Vector3(0.14f, 0.517f, 1);

      gesundheit = GameObject.Find("GUITextGesundheit");
      gesundheit.guiText.text = finalHealthScore;
      gesundheit.gameObject.transform.position = new Vector3(0.185f, 0.45f, 1);

      punkte = GameObject.Find("GUITextPunkte");
      punkte.guiText.text = finalPointScore;
      punkte.gameObject.transform.position = new Vector3(0.145f, 0.38f, 1);

And here's a screenshot of what this code actually looks like once the game is played:

Now that the game is finally finished, I need to start looking at getting the instructional materials assembled and creating lesson plans for the day on which the game will be tested in class. As I will also be working with human test subjects, I will need to get institutional IRB approval. All sorts of little things to keep an eye as the project moves forward!

Thursday, February 10, 2011

Beer Bottles (Nearly) Imported

The new semester has finally started and, as anticipated, I've been busy with teaching and course preparations. I'm glad that I had time over Winter Term to code the game, get the functionality figured out, and polish the game interface. I'm going to test the game prototype in about two months and, as it currently stands, I only have some minor tweaking to do and development of instructional resources.

The game will require students who play it to recycle bottles according to glass type: clear, brown, and green. This will allow students to practice vocabulary and grammar (German two-way prepositions, e.g.: Ich werfe die Flasche in  den Braunglascontainer), all within a simulated real-world context. For the last few weeks, however, I've had some difficulties getting the bottles to be "just right." Either I could make the entire bottle transparent, or none of it. Basically there was a problem with applying more than one texture to a single game object inside of Unity. I was finally able to solve this problem by composing one bottle out of several different objects, each of which had an unique textured applied to it. So, for instance, I was able to take a German beer label (which shouldn't be transparent):

And apply it to a beer bottle, which needs to be entirely transparent. So, I made an object for the label inside of Blender and applied the label as a texture before importing it into Unity. I did the same thing with the beer bottle, albeit with a space in the model where the beer label object would be inserted. Once inside Unity, I created a compound object composed of the the Blender objects. And here's the result:

A minor detail, perhaps, but one that I think adds a little extra layer of authenticity to the game, although I don't know whether the students will take time to think about the extra work that it entailed. Now that I got the clear and brown glass bottles finished, I just have to do the green glass bottles and non-recyclable  trash and the game will be mostly finished. And, by the way, Franziskaner Hefe-Weissbier is really good.