Well I am Working on a project for School, right now I am making a game where you are a cube that shoots smaller cubes that come out of spawners. When the smaller cubes hit you they cause me to loose a life which I have displayed. now, In order to make the game havea goal i want to base winning the levels on the number of the enemy cubes that I have destroyed. So what I need help with is making a Gui that will display how many kills I have gotten and when I get to a certain number of kills win the level and load a new level. right now I have a script that will display “SCORE: 0” but when I fire the lazer it appears to place another copy of the score gui on top of the first onebelow is the script i am using… i am am still very new to C# scripting so simplicity is key.
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Mouse0)) {
Instantiate(LaserPrefab, transform.position, Quaternion.identity);
}
}
}
As i can see, you put GUI script on a laser prefab, so, when you instantiate new copy of laser - you also create a copy of GUI function, and each of them draw label, until disabled or destroyed. Put OnGUI and Score in your master player script. Also, i recommend you to try static values for Score.
I wouldn’t call static anything near Intermediate. It’s just a variable that lives throughout the application.
Also, your example only makes it add the score when the bullet hits the enemy, hopefully the person asking the question isn’t a total begginer, because of a few things.
1: You demonstrated this using OnTriggerEnter without disposing of the GameObject. Get ready for the score to jump 500 times every bullet.
2: He might not even know what a “Trigger” is.
Not saying your example wasn’t in the correct direction, but it could lead to a whole new problem.
His enemies could have health and don’t die till they hit 0, etc. We need more information.