- Home /
Trying to turn is trigger on based on variable minimum score
Hi I'm new to unity, and just learning, so if I've missed the obvious, my apologies. I have a ball roller game set up with coin collecting, and a target paddle to hit once the minimum score is reached to move to the next level. The problem I'm having is getting the paddle's is trigger to only be true if the minimum score is 0 or less.
I have the variable currentScore in GameMaster.js
static var currentScore : int = 0;
which is then set to 2 in the script for testing purposes. (I plan to make it settable as a variable in each level once I've got it working properly.)
The script CoinPickup then subtracts the coin score from the minimum, and the GameMaster script updates the UI depending on the value
function OnGUI () {
if (minimumScore > 0)
{GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Collect " + minimumScore +" more coins to win");
}
else
{GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Hit the target to end level");
}
What I'm trying to do in the HitTarget script attached to the paddle, is make its trigger property toggle on or off depending on the minimum score.
What I have so far is:
function SetTrigger(){
if (GameMaster.minimumScore > 0){
//switch is trigger property on target to true
}
//switch is trigger property to false
}
}
function OnTriggerEnter( info : Collider){
// then load the next level
Application.LoadLevel(Application.loadedLevel + 1);
}
I want to use both a true and false in case I add enemies or traps to take points away at a later date, I want to be able to deactivate the target as well as activate it.
I've been chasing my tail around these boards all day, and I've tried several approaches, but don't seem to be able to pin down that last bit of code. Any help would be greatly appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220613153324im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Audio Toggle Background Music (With Trigger ) 2 Answers
Trigger not working 2D 1 Answer
Problems making an audio JumpScare 2 Answers
Toggle onPointerDown event 2 Answers
Destroy game object when player enters a box collider 1 Answer