D
D
Demigodd2017-03-13 17:08:50
Unity
Demigodd, 2017-03-13 17:08:50

How to make time pass when you move to another scene?

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

public class AddTable : MonoBehaviour 
{
    public float time;
    public Button BonusBbttn; 
    public GameObject Stopimage; 


    public void ActivateAfter() 
    {
        BonusBbttn.interactable = false;
        Stopimage.gameObject.SetActive(true);
        StartCoroutine(ActivateRoutine());
    }
 
    private IEnumerator ActivateRoutine() 
    {
        yield return new WaitForSeconds(time);

        BonusBbttn.interactable = true;
        Stopimage.gameObject.SetActive(false);
    }
}

Let's say there is a button when pressed, adds 500gold, and turns off for a certain time, when you switch to another scene and back again, the timer is reset and the button is active again. Decide to do it through Dont Destry, but there is generally a mess.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Oleg Pogrebnyak, 2017-03-13
@Demigodd

You save the DateTime of the origin in PlayerPrefs, and when loading a new scene you compare, if: DateTime (current) - DateTime (from PlayerPrefs) > time (here you need to multiply by a coefficient, most likely 10 million), then you call the coroutine with the expectation "time - ( dateTimeCurrent - dateTimePrefs) / 10,000,000.

A
Alexander, 2017-03-13
@NeiroNx

you need to save the state of the button on the server side (if the single is in saving the state of the game), and when entering the scene, simply request this state

M
murzik_a, 2017-12-22
@murzik_a

Telepathy doesn't work on Friday. Starting from the seven - it can start, but no one will give you 100%.

E
Ezhyg, 2017-12-22
@Ezhyg

For Windows, the operating mode of the disk controller is more important - there may be problems when switching to AHCI and back. It is easy to fix - before "updating" - changing the driver of the controller to which the boot disk is connected to a "standard IDE controller" or installing a SATA driver, depending on which direction the transition is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question