So, i have a points and pick up script, the things collected have the tag of Coins.
When i collect x amount of coins i want to trigger an event such as when character collects 10 'coins', the wall of cubes disappears?
I have no idea how to do this.
My pick up code is:
var score = 0;
var scoreText = "Score: 0";
var mySkin : GUISkin;
function OnTriggerEnter( other : Collider )
{
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin")
{
Debug.Log("Other object is a coin");
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
else
{
score +=5;
scoreText = "Score: " + score;
Debug.Log("Score is now " +score);
Destroy(other.gameObject);
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }
You must have a function to "pick up a coin". By your "points" I assume that every time a coin is picked up a point is added.
So in your function which "adds a point" you would want to do a check to see how many total points the player has. In this code I'm assuming your player coin count is a var called "playerCoins":
function pickUpCoin()
{
//all your coin picking up code
if (playerCoins == 10)
{
DoSomething(); //call the function to do something (destroy wall etc)
}
}
If you want something more in depth then edit the question and add your current code.
EDIT:
function OnTriggerEnter( other : Collider )
{
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin")
{
Debug.Log("Other object is a coin");
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
else
{
score +=5;
scoreText = "Score: " + score;
Debug.Log("Score is now " +score);
Destroy(other.gameObject);
}
if (score >= 10)
{
//do something
}
}