Question by
kingyfyvf · May 25, 2019 at 01:56 PM ·
c#c# tutorial
Breakout Ball not working
I've been following a simple Breakout tutorial on Unity but I cant seem to get the ball released from the paddle. It's a simple code but I can't seem to get it right. Any help is appreciated, here's the code:
using UnityEngine; using System.Collections;
public class ball : MonoBehaviour {
public float ballInitialVelocity = 600f;
private Rigidbody rb;
private bool ballInPlay;
void Awake () {
rb = GetComponent<Rigidbody>();
}
void Update ()
{
if (Input.GetButtonDown("Fire1") && ballInPlay == false)
{
transform.parent = null;
ballInPlay = true;
rb.isKinematic = false;
rb.AddForce(new Vector3(ballInitialVelocity, ballInitialVelocity, 0));
}
}
}
Comment
Do you get any error in the console? Have you tried to call Debug.Log
inside the Update
? (Outside and inside the if
)?