Example #1
0
 private void SetUpDayNight()
 {
     if (dayNightScript == null)
     {
         GameObject go = GameObject.FindGameObjectWithTag("DayNight");
         if (go)
         {
             dayNightScript = go.GetComponent <Cycle2DDN>();
         }
     }
 }
Example #2
0
    private void Awake()
    {
        if (_instance == null)
        {
            //if not, set instance to this
            _instance = this;
        }
        //If instance already exists and it's not this:
        else if (_instance != this)
        {
            //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
            Destroy(gameObject);
        }

        //DontDestroyOnLoad(gameObject);
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        // Sets the main DayNight handler.
        if (Handler != null && Handler != this)
        {
            Destroy(gameObject);
        }
        else if (Handler == null)
        {
            Handler = this;
        }

        // Sets the proper cycle duration for each of the 4 phases
        cycleUpdate = cycleTime / 4;

        // Creates new lists to store all the renderer variables.
        AnimatedSprites = new List <SpriteRenderer> ();
        StaticSprites   = new List <SpriteRenderer> ();
        MiscRenderers   = new List <Renderer> ();

        // Creates the proper colors for the screen darkening effect.
        scrnDay   = new Color(0, 0, 0, day.a);
        scrnDusk  = new Color(0, 0, 0, dusk.a);
        scrnNight = new Color(0, 0, 0, night.a);
        scrnDawn  = new Color(0, 0, 0, dawn.a);

        // Resets the default colors' alpha to 255.
        day   = new Color(day.r, day.g, day.b, 1);
        dusk  = new Color(dusk.r, dusk.g, dusk.b, 1);
        night = new Color(night.r, night.g, night.b, 1);
        dawn  = new Color(dawn.r, dawn.g, dawn.b, 1);

        // Gets the image needed for the darkening effect.
        screenDark = GetComponentInChildren <Image> ();

        // Jumps to the specified starting cycle.
        JumpToCycle(startingCycle);

        // Starts the delay and the static updates.
        StartCoroutine("StartDelay");
        InvokeRepeating("UpdateStatic", cycleStartDelay, staticUpdateFreq);
    }