unity stop time code example
Example: time stop unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Example : MonoBehaviour
{
bool timeOff; //Set a bool to know when the time is off
public void TimeOff() //Make a public void to reference
{
Time.timeScale = 0f; //Set the time to 0f
}
public void TimeOn()
{
Time.timeScale = 1f; //Set the time to 1f
}
void Start() //You don't need a start method so you can delete it if you want
{
}
void Update() //You do need the Update Method
{
if(timeOff) //We need an if() statement here
{
TimeOff(); //Reference TimeOff();
timeOff = true; //Set the bool to true
}else if(timeOff) //Add an else if statement here
{
TimeOn(); //Reference TimeOn();
timeOff = false; //Set the bool to false
}
}
//Now after the code is saved, click on the button that will trigger your TimeOff() and add a OnClick Event to it and Reference TimeOff
//Now click on the button that will go back to the game and add a OnClick Event to it and Reference the TimeOn() void
}