using System.Collections.Generic;
using UnityEngine;
public class ball : MonoBehaviour
{
[SerializeField] paddle paddle;
Vector2 diffPos;
// Start is called before the first frame update
void Start()
{
diffPos = transform.position - paddle.transform.position;
}
// Update is called once per frame
void Update()
{
Vector2 paddlePos = new Vector2(paddle.transform.position.x, paddle.transform.position.y);
transform.position = paddlePos + diffPos;
}
}
WHEN THE CODE GETS EXECUTED THE Z AXIS OF MY BALL CHANGES AND NOT STAYS THE SAME. Why does this happen? But I didn’t change my z axis . It automatically changes when the ball script runs? can you explain why and a solution ?