Button not working

Hello, I am currently working on my first game in unity.
I have made it so, that when your lose after x collisions, you are taken to a restart scene, where there is a restart button, which is supposed to bring you back to the actual game.

The way I did this was:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class RestartController : MonoBehaviour
{
public void RestartControl()
{
SceneManager.LoadScene (“SampleScene”);
}
}

I added this script to my restart button object and then dragged the button into the onclick event and fixed the stuff there.

When I have x collisions, I am being taken to the restarting scene, so that works. But when I click on the restart button, I quickly see the actual game scene, but then it immediately flashes back to the restarting scene.

Can anyone help me out please?
Thanks already!

You probably forgot to reset the variable that counts collisions. You go to the original scene, which immediately notices that you have too many collisions and sends you back.

It also means you’re probably checking collision count in Update. If so, it would be more efficient to do it when the collision occurs.

1 Like

Thank you SO MUCH MAN!!
I have been looking everywhere on the internet, but couldn’t find the solution. Didn’t know it was that simple.

Really appreciate your reply man!!

Happy to help!

1 Like