Part 5 – Scoreboard script






Script for Part 5

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pickup : MonoBehaviour {

    public int iLevel = 1;  //ACTUAL LEVEL
    public Texture2D textureToDisplay;  //PICTURE FOR LEVEL 1

    private string sText = "SCORE: ";
    private int iScore = 0; //Actual Score
    private int iCount = 10; //Number of objects that we must find at level
   
    // Use this for initialization
    void Start ()
    {
	}
	
	// Update is called once per frame
	void Update ()
    {
	}

    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("PickUp " + iLevel.ToString()))
        {
            Destroy(other.gameObject);
            iCount = iCount - 1;
            iScore = iScore + 10;
        }
    }

    private void OnGUI()
    {
        int iXPos = 10;

        GUIStyle myStyle;
        myStyle = new GUIStyle();
        myStyle.fontSize = 24;
        myStyle.normal.textColor = Color.black;

        GUI.Label(new Rect(10, 10, 3000, 10000), sText + iScore.ToString(), myStyle);

        for(int i=1; i<=iCount;i++)
        {
            GUI.Label(new Rect(iXPos, 40, 40, 40), textureToDisplay);
            iXPos += 50;
        }

    }
}


Microsoft Exchange SAN UCC SSL