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;
}
}
}
`