- Home /
How to make only one ball bounce?
I want to make it so, that when i touch a ball it jumps up, but now when i touch a ball all of them jump. I'm really tired so i'm really sorry if i don't make any sense. But anyways here's my code. Hopefully someone can fix it :) This is also my first post ever on unity. So pardon my noobness.
public Vector2 jumpForce = new Vector2(0, 300);
void Update () {
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero);
if (hit != null && hit.collider != null) {
Debug.Log ("BOUNCE "+hit.collider.name);
rigidbody2D.velocity = Vector2.zero;
rigidbody2D.AddForce(jumpForce);
}
}
}
Comment
void On$$anonymous$$ouseDown() {
rigidbody2D.AddForce(jumpForce);
}
I don't think you need to raycast. the On$$anonymous$$ouseDown is called when THIS gameobject has been clicked. So I think this may work.
Your answer
Follow this Question
Related Questions
Convert WASD (or arrows) to touch input for ball maze game 0 Answers
I WANT TO MAKE MY BALL JUMP :( 2 Answers
Jumping Ball 1 Answer
How do I define the speed of my player in the y axis? 3 Answers
How To Make Ball Bounce On Touch 1 Answer