Quantcast
Channel: Questions in topic: "count"
Viewing all articles
Browse latest Browse all 187

How to Update a score count going up and down

$
0
0
Hi I'm trying to make it so that when a ball hits the ground, the score count goes down by 1. I already have it where if the ball hits a moving box, then the score count goes up by 1, which is fine. But with my code right now, if my score count is at lets say, 30. And if the ball hits the ground, I'd want it to go down to 29. But right now if the ball hits the ground, it starts at 0 and goes down to -1. And when the ball hits the box it goes back to the previous score of 30 and bumps it up to 31. Any help would be appreciated, thanks! public GameObject ball; public Text countText; public float volume; public AudioClip SoundToPlay; AudioSource audio; private int count; void Start() { count = 0; SetCountText (); audio = GetComponent (); } void OnTriggerEnter2D (Collider2D paddleTrigger) { if (paddleTrigger.CompareTag ("ball")) { count = count + 1; SetCountText (); audio.PlayOneShot (SoundToPlay, volume); } } void SetCountText() { countText.text = "" + count.ToString (); } //This script ABOVE ^^^^^^^^^^ is for the count to go UP when hitting the box (paddle) //This script BELOW vvvvvvvvvv is for the count to go DOWN when hitting the ground public GameObject ball; public Text countText; public float volume; public AudioClip SoundToPlay; AudioSource audio; private int count; void Start() { audio = GetComponent (); this.GetComponent ().enabled = false; } void UpdateCount() { SetCountText (); } void OnTriggerEnter2D (Collider2D groundTrigger) { if (groundTrigger.CompareTag ("ball")) { count = count - 1; SetCountText (); audio.PlayOneShot (SoundToPlay, volume); } } void SetCountText() { countText.text = count.ToString (""); } }

Viewing all articles
Browse latest Browse all 187

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>