Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class InGameVis : MonoBehaviour {
- GameObject courseObject;
- Course4 courseScript;
- float width; float height;
- public bool ready = false;
- string toMove = "Move left and right with '" + Player4.leftKey
- + "' & '" + Player4.rightKey + "'";
- string toJump = "\nJump with " + Player4.jumpKey + "bar";
- string toPlatform = "\nActivate platform for next jump with '" + Player4.upPlatformKey + "'";
- string toDrop = "\nDestroy a block you're standing on with '" + Player4.dropKey + "'";
- string instrText;
- string scoreText = "Blocks used: ";
- int scoreVal = 0;
- string prevScoreText = "Fewest blocks used so far: ";
- int prevScoreVal = 10000;
- bool muted = false;
- void Start() {
- // DontDestroyOnLoad( gameObject );
- PlayerPrefs.SetInt("prevScoreVal", 10000);
- courseObject = GameObject.Find("buildCourse");
- courseScript = (Course4) courseObject.GetComponent("Course4");
- width = Screen.width - 50;
- height = Screen.height - 75;
- scoreVal = courseScript.score;
- instrText = toMove + toJump + toPlatform + toDrop;
- ready = true;
- // This logs as True
- Debug.Log("[InGameVis] OnGUI(): ready " + ready);
- }
- //
- public void StartGameGUI () {
- // courseObject = GameObject.Find("buildCourse");
- // courseScript = (Course4) courseObject.GetComponent("Course4");
- //
- // width = Screen.width - 50;
- // height = Screen.height - 75;
- //
- // scoreVal = courseScript.score;
- //
- // instrText = toMove + toJump + toPlatform + toDrop;
- //
- // ready = true;
- // // This logs as True
- // Debug.Log("[InGameVis] OnGUI(): ready " + ready);
- }
- void OnGUI () {
- // This always logs as False
- Debug.Log("[InGameVis] OnGUI(): ready " + ready);
- if ( ready ) {
- // INSTRUCTIONS
- GUI.Label( new Rect(10, 5, 1000, 300), instrText );
- // BUTTONS
- // xCoord = screenWidth - (width + margin)
- if ( GUI.Button(new Rect(470,10,70,20),"Restart") ){
- Goal.resetWon();
- if ( PlayerPrefs.GetInt("prevScoreVal") > scoreVal ) {
- PlayerPrefs.SetInt("prevScoreVal", scoreVal);
- }
- Application.LoadLevel(Application.loadedLevel);
- muted = false;
- }
- if ( !muted ) {
- // xCoord = screenWidth - (width + margin)
- if ( GUI.Button(new Rect(470,35,70,20),"Mute") ){
- AudioListener.pause = true;
- muted = true;
- }
- } else {
- // xCoord = screenWidth - (width + margin)
- if ( GUI.Button(new Rect(470,35,70,20),"Un-mute") ){
- AudioListener.pause = false;
- muted = false;
- }
- } // end if !muted
- // SCORES
- scoreVal = courseScript.score;
- // 20.5 * height/21
- GUI.Label( new Rect(325, 372, 1000, 300), (scoreText + scoreVal) );
- PlayerPrefs.GetInt("prevScoreVal");
- // 3.5 * height/21
- if ( PlayerPrefs.GetInt("prevScoreVal") < 10000 ) {
- GUI.Label( new Rect(300, 65, 1000, 300), (prevScoreText + PlayerPrefs.GetInt("prevScoreVal")) );
- } else {
- GUI.Label( new Rect(300, 65, 1000, 300), (prevScoreText + "-") );
- }
- } // end if ready
- } // End OnGUI()
- // Allow something to give the right widths and heights
- public float[] setDimensions ( float newWidth, float newHeight ) {
- width = newWidth;
- height = newHeight;
- float[] dimensions = new float[2] {width, height};
- return dimensions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement