Hello I’ve been working on a power up script which is included in a scoring script. However I’m not sure how to hide the GUI power-up button after it has been activated, until it becomes deactivated. The problem is that GUI button can be accidentally clicked multiple times, reducing the player’s score each time it’s clicked.
I incorporated the code,
var script6 = GetComponent("ScriptName");
script6.enabled = false/true;
which has worked but it hides the score as well as the button. Is there some way to work around this?
Here is the full script, which includes the scoring system, just in case:
var score = 0;
var DeductSlowDownScore = 110;
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 += 160;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
else if (other.tag == "Rock" score > 0) {
Debug.Log("Other object is a rock");
score += -120;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
}
else if (other.tag == "Tree" score > 0) {
Debug.Log("Other object is a tree");
score += -95;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
}
else if (other.tag == "GoldPickup" score > 0) {
Debug.Log("Other object is a goldpickup");
score += 250;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Box (Rect (140, 10, 500, 200), scoreText.ToString());
if (GUI.Button (Rect (5, 5, 110, 60), "Slow Down")) {
StartCoroutine( SlowDown( 1.5 ) );// deactivate for 1.5 secs
}
}
function SlowDown(deactivateInSeconds : float)
{
var script4 = GetComponent("Raft Forward - Hard");
script4.enabled = false;
var script5 = GetComponent("RaftForwardEasier - Hard");
script5.enabled = true;
yield WaitForSeconds(deactivateInSeconds);
script5.enabled = false;
script4.enabled = true;
score = score - DeductSlowDownScore;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
};
I apologize if the question is difficult to answer
Thank you for any answers or feedback. -Ben