Hi can u tell me whats wrong with the game 2d

so every time i play me block breaker i made it loads to the next scene without a button

code

> using System.Collections;
> 
> using System.Collections.Generic;
> 
> using UnityEngine;
> 
> using UnityEngine.SceneManagement;
> 
> public class SceneLoader : MonoBehaviour {
> 
>     public void LoadNextScene()
> 
>     {
> 
>         int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
> 
>         SceneManager.LoadScene(currentSceneIndex + 1);
> 
>     }
> 
>     public void LoadStartScene()
> 
>     {
> 
>         SceneManager.LoadScene(0);
> 
>     }
> 
>     public void QuitGame()
> 
>     {
> 
>         Application.Quit();
> 
>     }
> 
> }

Hi Ahmed,

Could you please elaborate a bit further on what you did in your project and what your problem is? At the moment, all I know is that the next scene gets loaded without a button, which does not sound like a problem to me.

yes but i dont want it do that until i lose

and i still havent lost or won so

Unity’s physic engine is highly optimised meaning it checks the position of a collider occasionally only. You could try to set the Collision Detection mode of the ball’s Rigidbody2D to “Continuous”. In most cases, that fixes the problem.

In our particular case, the problem is that we manipulate the transform.position via code and override the calculated values of the physics engine. It is likely that the position of the ball does not match the position of the collider anymore.

A better solution would be to disable the physics simulation for the ball while manipulating the position via code.

void Start ()
{
    paddleToBallVector = transform.position - paddle1.transform.position;
    myAudioSource = GetComponent<AudioSource>();
    myRigidBody2D = GetComponent<Rigidbody2D>();
    myRigidBody2D.simulated = false; // <-------- add this
}
 
private void LaunchOnMouseClick()
{
    if (Input.GetMouseButtonDown(0))
    {
        hasStarted = true;
        myRigidBody2D.velocity = new Vector2(xPush, yPush);
        myRigidBody2D.simulated = true; // <-------- add this
    }
}

I hope that makes sense. :slight_smile:


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms