- Home /
Question by
marksus · Nov 28, 2014 at 12:46 AM ·
Updating a collision inside function update?
Hi there. I'm making a basic pong game with unity. So far have it working and everything is great. I am trying to make the ballspeed increase every time the player hits the ball. I setup a debug.log showing the ballspeed increase but nothing seems to happen. If i hit reset game the ballspeed will then be at the appropriate speed. Simply because the game is not updating the ballspeed. here's what i have.
function OnCollisionEnter2D (colInfo : Collision2D) {
if (colInfo.collider.tag == "Player"){
ballSpeed = ballSpeed + 10;
Debug.Log("ballSpeed is " + ballSpeed);
//straighten out ball when not moving player
rigidbody2D.velocity.y = rigidbody2D.velocity.y/2 + colInfo.collider.rigidbody2D.velocity.y/3;
audio.pitch = Random.Range(0.8f,1.2f);
audio.Play();
}
}
any idea how I could get the ballspeed to update of the fly? Thanks!
Comment
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Move Towards Target Color 2 Answers
Gradually reduce speed 1 Answer
How do we instantiate random sprites from an array... 1 Answer
End game after livesLeft = 0 0 Answers