Beginner bouncy balls

Hi

I am a beginner to unity. I have made a very basic game where I have 2 balls that bounce.
Basically I now want to start with the balls on the ground and on a click of a button (developing for mobile devices) the balls will be pushed to make them bounce.

Any help??

Thanks

You can use GUI.Button to make a button, and make the balls start bouncing when you press it.

See also:

On the GUI script you can have something like:

private var ball1 : GameObject;
private var ball2 : GameObject;
// Declare strength for the bounce, you may need to edit this!
var bounceStrength : float = 100;

Start(){
// Find the references to your balls. Remember to create tags for your balls
// and assign those tags appropriately "Ball1" and "Ball2"
ball1 = GameObject.FindWithTag("Ball1");
ball2 = GameObject.FindWithTag("Ball2");
}

OnGUI(){
    // Button 1 for bouncing ball 1
    // Note that you'll have to replace Rect() variables with your own
    if (GUI.Button(Rect(posX, posY, btnWidth, btnHeight), "Bounce 1"))
    {
        // Add upwards force to the ball
        // Alternatively you can use Vector3(xForce, yForce, zForce)
        ball1.rigidbody.AddForce(Vector3.up * bounceStrength);
    }
    // Place button for ball 2 150 pixels to the right from the start of button 1
    if (GUI.Button(Rect(posX + 150, posY, btnWidth, btnHeight), "Bounce 2"))
    {
        ball2.rigidbody.AddForce(Vector3.up * bounceStrength);
    }
}

I hope this helps you get those balls bouncing. Just remember to assign the tags to the ball objects, add rigidbody components to the balls and of course change the Rect() variables of the buttons so you’ll have them where you want them.

SheepHugger out.