Im making this basic platformer game and I added a restart function but when i run the game the scene doesn't reload here is my code Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PlayerLife : MonoBehaviour { private Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("Trap")) { Die(); } } private void Die() { rb.bodyType = RigidbodyType2D.Static; } private void RestartLevel() { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } }
I don't really know what the question is about. As for the method itself, it's correct, you just don't call it anywhere. Logically, the level restart is probably after the character dies, so put the RestartLevel() call inside the Die().