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
http://forum.unity3d.com/forums/12-Scripting
But you'll want to add these lines to your OnCollisionEnter function;
score -= 1;
UpdateScoreText();
Either via the vase object's name, or a component attached to it or it's tag...
Then do +=1 or -=1 depending on which.