- Home /
Question by
Doctor_Fork · Jul 02, 2021 at 05:52 PM ·
scorecoroutinesscore system
Object falling over triggers way too many times
So I have a set of code that when a bowling pin falls over, it's supposed to make the score go up by 1 for my bowling game. However, it doesn't do it by 1, but somewhere between 110 and 130. Here's the code:
public class PinFall : MonoBehaviour
{
public bool isgrounded = true;
public ParticleSystem ExplosionNoDelay;
void Start()
{
ExplosionNoDelay.Play();
}
void Update()
{
if (isgrounded == false)
{
StartCoroutine(ExecuteAfterTime(2));
}
}
void OnCollisionEnter(Collision theCollision)
{
if (theCollision.gameObject.name == "floor")
{
isgrounded = true;
}
}
void OnCollisionExit(Collision theCollision)
{
if (theCollision.gameObject.name == "floor")
{
isgrounded = false;
}
}
IEnumerator ExecuteAfterTime(float time)
{
yield return new WaitForSeconds(time);
ExplosionNoDelay.Play();
Destroy(gameObject, 0.3f);
ScoreScript.scoreValue += 1;
StopCoroutine(ExecuteAfterTime(2));
}
}
How would I make it so the score only goes up by 1 each time? (this goes on the pin itself so it repeats for each pin)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613035740im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to get my spawn manager to respond to the current score 1 Answer
Score counter breaking after adding points 2 Answers
I am trying to add additional score to my current timed score but cannot find how to do this 0 Answers
Counting points constantly, without framerate dependency 3 Answers
Why my score system not working? 1 Answer