My game is making copies of the paddle and the ball. whenever I push play on unity, it just starts to make copies of the paddle and the ball.My teacher checked my code and told me that ,the code is correct ,there is nothing wrong in it. So if anyone had this problem once ,then please tell me how to solve it.
Hi, can you share your code? Perhaps just the bit where you create the paddle.
Most probably, a script is creating a new paddle every frame, instead of just once when the game starts.
here is my paddle script:
public class paddle : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
float MousePosinx = Input.mousePosition.x / Screen.width * 22f -11f;
Vector3 paddlepos = new Vector3(MousePosinx, transform.position.y, transform.position.z);
transform.position = paddlepos;
}
}
here is my ball script:
public class ball : MonoBehaviour
{
//public Audioclip brickHit;
//public Audioclip wallHit;
public GameObject spawnPoint;
bool hasStarted = false;
// Use this for initialization
// Update is called once per frame
void Update(){
if (hasStarted == false)
{
LockBallToPaddle();
LaunchBall();
}
}
void LockBallToPaddle()
{
Vector3 SpawnPos = new Vector3(spawnPoint.transform.position.x, spawnPoint.transform.position.y, spawnPoint.transform.position.z);
transform.position = SpawnPos;
}
void LaunchBall()
{
if (Input.GetMouseButtonDown(0))
{
hasStarted = true;
GetComponent<Rigidbody>().velocity = new Vector2(2f, 15f);
}
}
//private void OnCollisionEnter(Collision collision)
//{
// if (collision.gameObject.tag == "floor"){
// hasStarted = false;
// }
//}
}
Could it just be that the screen is not being cleared?
1 Like
Yes indeed your script looks ok.
I think @Tartiflette 's suggestion is a great thing to look at next. Check the camera is set to Clear to a Solid Color, and not set to None.
Thank you that worked.
I think your problem is solved. if you still have a question. discuss.