- Home /
Finding number of bowling pins knocked over
I'm making a Unity 3D bowling game but haven't figured out how to tally up the number of pins knocked after the ball has hit.
I have tried noticing when the pins rotation has changed but it doesn't seem to work.
I am destroying the ball and that is how the level ends so and instantiates the next level.
Below is the code I added to the pin.
Do I need to have an on-collision event for this script to be called. Currently my console just prints "Pin is Standing" the whole time.
public class Pin : MonoBehaviour {
public int score;
public void Update()
{
TallyScore();
}
public void TallyScore()
{
//checking if the pin is standing up (if it's not, the pin's rotation will be not 0)
if (transform.rotation.x < 1 && transform.rotation.z < 1)
{
Debug.Log("Pin is standing");
}
else
{
//pin is knocked over
score++;
Debug.Log(score);
}
}
public int getScore()
{
return score;
}
}
Answer by mlnczk · Nov 23, 2018 at 01:08 PM
Add collider to middle or on top of your pin prefab. Then check OnCollissionTrigger with ground collider and add it to global score controller by other object.
Your answer
Follow this Question
Related Questions
Collision problem 4 Answers
Flip over an object (smooth transition) 3 Answers
Collision detection from specific directions using rigid body character? 0 Answers
Camera bounce back? 0 Answers