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);
Application.LoadLevel("final_screen");

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!

4 comments:

  1. Wait, wait, wait! The game is finished?

    ReplyDelete
  2. Well, the prototype version of the game is finished, I suppose. Although there's still a lot I'd like to add (characters, more interface candy), I think that there's enough for me to test it out on students. If I get some grant money, I'll work on developing the game some more. If I don't get grant money, well, I'll probably do the same thing.

    ReplyDelete
  3. Ooh! Ooh! can I help test it?

    ReplyDelete
  4. I'm going to put everything I developed online (game, source code, Blender models, etc.), so you are more than welcome to look at it and see what needs to be changed.

    ReplyDelete