I’m making breakout game, and i did simple lose, that shows lose text and button(restart game)
if(amountOfBalls < 1)
{
looseScreen.SetActive(true);
Time.timeScale = 0;
}
The problem is when i restart game(by this code*)
public void RestartGame()
{
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name);
} *
My ball just spawns and don’t do anything, but when i loaded my game with unity, everything was working, if i lose and press button “replay” everything fine except the ball, it’s simply not going but i checked and don’t see any problems there, speed - fine, rigidBody - working, x and y - ok, timeScale = 1. Ball spawn by GameManager script, but other ball logic contains in the ball Script, here ball script:
public class ball : MonoBehaviour
{
public float speed;
protected Rigidbody2D rb;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
AddStartingForce();
}
public void AddStartingForce()
{
float x = Random.value < 0.5f ? -1 : 1f;
float y = Random.value < 0.5f ? 0.7f : 1.2f;
rb.AddForce(new Vector2(x, y) * speed * Time.deltaTime);
}
}
And here ball spawns by another script(GameManager):
private void Start()
{
Time.timeScale = 1;
Instantiate(ball);
amountOfBalls++;
}
i’ll be really appreciate if you help me, please, ask questions if you need