- Home /
Increasing a Variable on Collision
Hello, I am currently working on a Pong game (because it is basic and I am new) using Unity Javascript. I want to have a score system that is increased every time the ball collides with your player, as well as the typical score (already got that). I am pretty unfamiliar with the rigidbody system, so would anyone be able to notify me of a way to increase a variable on collision?
Answer by save · Sep 20, 2012 at 06:33 PM
In the example the script Scores has a static int variable with name bounces, bounces gets added to each collision if it's the ball.
function OnCollisionEnter (collision : Collision) {
if (collision.collider.tag!="Ball") return;
Scores.bounces++;
}
Answer by jmane2012 · Sep 20, 2012 at 07:11 PM
Hey that worked, thanks! I changed it up a tad bit to better fit what I was looking for though.
function OnCollisionEnter (collision:Collision) { if(collision.collider.tag != "Player") return; playerPoints += 50;
}
I am trying to add special features like increasing the force on the ball to throw it in the direction of the enemy and going to be adding blocks to make it harder to score for the enemy depending on how many points you have.
Your answer
![](https://koobas.hobune.stream/wayback/20220613081258im_/https://answers.unity.com/themes/thub/images/avi.jpg)