12 – GuiText, Collisions, and Adding Scores

This entry is part 12 of 13 in the series Unity 3D

12 - GuiText, Collisions, and ScoresAdding Scores with GUIText

In this Unity 3D tutorial we will be adding scores to our game. Eventually, we will save the highscore within our application.  It is recommended that you take this course with a friend so you can work together and keep each other accountable.  mybringback would also love if you could tweet this course out to your friends, or post on facebook.  I wish you the best as a future game developer. -Trav

Video Lesson


In this Unity tutorial we will learn how to destroy objects if a specific collision is made. What I mean is, if our ball collides with a Brick object destroy the Brick and add 10 to the score, if it collides with a rock, do nothing. The other part of this tutorial involves adding public variables to our script that we can link up in unity. We will learn how to interact with a gameObject of the type GUIText.

Source Code

#pragma strict

private var score : int = 0;
var guiScore : GUIText;

function Start () {
	guiScore.text = "Score: 0";

function Awake(){
	rigidbody.velocity.x = 10;
	rigidbody.velocity.y = 10;

function Update () {


function OnCollisionEnter(col : Collision){
	if(col.collider.name == "Brick"){
		score += 10;
		guiScore.text = "Score: " + score;
		print("collide with brick");


Previous Lesson
Next Lesson

Author: trav

I'm just an average guy that love programming.

Share This Post On

Submit a Comment

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>