The ball launches when I click the mouse. However, it stays with the paddle—if I move right, the ball moves right and if I move left, the ball moves left. I’m using Unity 2017.1.2f1 Here is my ball script:
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour
{
public Paddle paddle;
private bool hasStarted = false;
private Vector3 paddleToBallVector;
// Use this for initialization
void Start()
{
paddleToBallVector = this.transform.position - paddle.transform.position;
}
// Update is called once per frame
void Update()
{
if (!hasStarted)
{
this.transform.position = paddle.transform.position + paddleToBallVector;
if (Input.GetMouseButtonDown(0))
{
print("Mouse clicked, launch ball");
hasStarted = true;
gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2 (2f, 12f);
}
}
}
}