Home Technical Talk

UNITY3D: Update Score when character collides with vase

manilamerc
polycounter lvl 6
Offline / Send Message
manilamerc polycounter lvl 6
Right now I have score code that updates by 10 when I click on the screen but I want to have it so when my character collides with the vase the vase disappears and it updates the score. Have no idea if all this needs to be in an Update function or what. Someone please help.
var vase : String = "Bob";
private var scoreText:GUIText;
private var score:int;

function Start ()
{
//intialize our variables listed

score = 0;

scoreText = GameObject.Find("GUI_Score").GetComponent(GUIText) ;
//call update function to update text
UpdateScoreText();

}

function Update ()
{
//if left click of left ctrl is pressed
if(Input.GetButtonDown("Fire1"))
{
//upate score variable
score += 10;

//call update function to update text
UpdateScoreText();
}

}

function UpdateScoreText()
{
//update the GUI Text on screen
scoreText.text = "Score: " + score;
}





function OnCollisionEnter(c:Collision)
{
if (c.gameObject.name == "vase" )
{
Destroy(c.gameObject); // destroys the thing this script bumped into

}

}

Replies

Sign In or Register to comment.