I've been trying to make it where when the player does a certain task, the game's time will pause. When the player does another action, the game's time would unpause and continue. I had my code like so:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class timeScript : MonoBehaviour { //uGUI Items public Text date; public Text playerCash;

public static int week;
public static int month;
public static int year = 1980;
//amount of cash
public static int myCash = 10000;
public AlertBox alert;
public Text timeText;

bool timeActive = true;
int time;

int day;

void Start()
    InvokeRepeating("Timer", 0, 1);

public static void Timer()
    timeText.GetComponent<Text>().text = "W" + week.ToString() + "" + year.ToString();

    playerCash.GetComponent<Text>().text = "$" + myCash.ToString();

    #region YEAR
    //Check if month equals 13 (allows for 12th month to be counted)
    if (month == 13)
        month = 0;
    #region MONTH
    //Check if week equals 5 (allows for 5th week to be counted)
    if (month == 5)
        week = 0;
    #region WEEK
    //Check if day equals 8 (allows for 7th day to be counted)
    if (day == 8)
        day = 0;
    #region DAY
    //Check if Time equals 5 (allows for 4 seconds)
    if (time == 2)
        time = 0;

I tried using CancelInvoke(timeScript.Timer()); in another c# file but all it did was give me an error that stated I couldn't convert from string to void.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.