If someone could please advise. Seems to be right, I tried going in adjusting, looking over unity, and googling, but still does not seem to work. Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
//config parameters
[SerializeField] Paddle paddle1;
//state
Vector2 paddleToBallVector;
// Start is called before the first frame update
void Start()
{
paddleToBallVector = transform.position - paddle1.transform.position;
}
// Update is called once per frame
void Update()
{
LockBallToPaddle();
LaunchOnMouseClick();
}
private void LaunchOnMouseClick()
{
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody2D>().velocity = new Vector2 (2f, 15f);
}
}
private void LockBallToPaddle()
{
Vector2 paddlePost = new Vector2(paddle1.transform.position.x, paddle1.transform.position.y);
transform.position = paddlePost + paddleToBallVector;
}
}