Adding 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
Description
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"){
Destroy(col.gameObject);
score += 10;
guiScore.text = "Score: " + score;
print("collide with brick");
}
}
