Hello I have a simple score script and a power up script, both are separate. What I’m wondering is if it’s possible to somehow link the two so that when the power up is activated some score is taken away? Basically when you click on the power up you lose a bit of your score in exchange for using it. Here’s the scoring script:
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 += 115;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
else if (other.tag == "Rock" && score > 1) {
Debug.Log("Other object is a rock");
score += -75;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
}
else if (other.tag == "Tree" && score > 1) {
Debug.Log("Other object is a tree");
score += -50;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Box (Rect (140, 10, 500, 200), scoreText.ToString()); }
And here is the power up script:
var mySkin : GUISkin;
function OnGUI () {
GUI.skin = mySkin;
if (GUI.Button (Rect (10, 50, 110, 60), "Slow Down")) {
StartCoroutine( SlowDown( 1.5 ) );// deactivate for 1.5 secs
}
}
function SlowDown(deactivateInSeconds : float)
{
var script4 = GetComponent("Movement");
script4.enabled = false;
var script5 = GetComponent("Movement - Easier");
script5.enabled = true;
yield WaitForSeconds(deactivateInSeconds);
script5.enabled = false;
script4.enabled = true;
}
I’m a little unsure on how to go about doing this. Many thanks for any answers or feedback. -Ben