Time freeze

hy guys! in my game, when the player collides with an object, i want to display a “restart” screen(UI) and freeze the time.
My problem is, whenever the player hits the object, restart screen appear, but the time doesnt freeze, only when they collide for the second time.
here is my player’s code.`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class controlls : MonoBehaviour {

public float speed = 600f;

public Joystick joystick;
public GameObject restart;

public GameObject UI;

float movementx = 0f;

private void Start() {
    restart.SetActive(false);
}

void Update() {

    movementx = joystick.Horizontal;

}

private void FixedUpdate() {
    transform.RotateAround(Vector3.zero, Vector3.forward, movementx * Time.fixedDeltaTime * -speed);
}

private void OnTriggerEnter2D(Collider2D other) {
    if (other.CompareTag("hexa")) {
        restart.SetActive(true);
        UI.SetActive(false);
        Time.timeScale = 0;
    }
}

}

`

Hi there,

This might be caused if one of your other game objects (UI or restart) is disabling/interfering with this code (controlls).

You should try putting the Time.timeScale line before you use the SetActive():

 private void OnTriggerEnter2D(Collider2D other) {
     if (other.CompareTag("hexa")) {
         Time.timeScale = 0;
         restart.SetActive(true);
         UI.SetActive(false);  
     }
 }

Or alternatively you could put the Time.timeScale line in the restart game object’s code.

So then when you do restart.SetActive(true) it will run the restart code and do the timeScale manipulation.