Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (isDay)
        {
            currentTime = Time.time - startTime;

            // Handle triggering child needs
            // Handle need processing
            if (Time.time - timeSinceNeed > timeToNeed)
            {
                child.TriggerNeed(currentTime / lengthOfDay);
            }

            // Update UI Timer Display
            myUI.SetUITime(currentTime / lengthOfDay);


            // Detect end of day
            if (currentTime >= lengthOfDay)
            {
                startTime = Time.time;
                //currentStage++;
                isDay = false;
                Debug.Log("Starting Intermission");

                levelObjects[currentLevel].SetActive(false);
                overlayFog.GetComponent <SpriteRenderer>().enabled       = true;
                child.gameObject.GetComponent <SpriteRenderer>().enabled = false;
                hand.ForceDrop();
                child.ForceNeedClear();
                child.Respawn();
                canvas.SetActive(false);
                if (currentLevel == 0)
                {
                    toddlerIntermission.enabled = true;
                    audioSource.loop            = false;
                    audioSource.clip            = toddlerIntroClip;
                    audioSource.Play();
                }
                if (currentLevel == 1)
                {
                    childIntermission.enabled = true;
                    audioSource.loop          = false;
                    audioSource.clip          = childIntroClip;
                    audioSource.Play();
                }
                if (currentLevel == 2)
                {
                    teenIntermission.enabled = true;
                    audioSource.loop         = false;
                    audioSource.clip         = teenIntroClip;
                    audioSource.Play();
                }
                if (currentLevel == 3)
                {
                    oldmanIntermission.enabled = true;
                    audioSource.loop           = false;
                    audioSource.clip           = oldmanIntroClip;
                    audioSource.Play();
                }
            }
        }
        else
        {
            currentTime = Time.time - startTime;
            myUI.SetUITime(0);


            // Detect end of day
            if (currentTime >= lengthOfIntermission)
            {
                isDay     = true;
                startTime = Time.time;
                canvas.SetActive(true);

                toddlerIntermission.enabled = false;
                childIntermission.enabled   = false;
                teenIntermission.enabled    = false;
                oldmanIntermission.enabled  = false;

                // Check if it is time to go to the next age
                //if(currentStage == levelStages)
                //{
                //currentStage = 0;
                currentLevel++;
                switch (currentLevel)
                {
                case 0:
                    child.AgeChild(ChildController.STAGE.BABY);
                    audioSource.loop = true;
                    audioSource.clip = babyMusicClip;
                    audioSource.Play();
                    break;

                case 1:
                    child.AgeChild(ChildController.STAGE.TODDLER);
                    audioSource.loop = true;
                    audioSource.clip = toddlerMusicClip;
                    audioSource.Play(); break;

                case 2:
                    child.AgeChild(ChildController.STAGE.CHILD);
                    audioSource.loop = true;
                    audioSource.clip = childMusicClip;
                    audioSource.Play(); break;

                case 3:
                    child.AgeChild(ChildController.STAGE.TEEN);
                    audioSource.loop = true;
                    audioSource.clip = teenMusicClip;
                    audioSource.Play(); break;
                }
                if (currentLevel > lastLevel)
                {
                    // We have finished the game... go to status screen
                    child.SaveStats();
                    Debug.Log("You have finished the game... results time!");
                    SceneManager.LoadScene(finishScene);
                }
                //}
                child.MoveChild(childSpawnPoint[currentLevel]);
                Camera.main.orthographicSize   = cameraSizePerLevel[currentLevel];
                Camera.main.transform.position = new Vector3(cameraPositionPerLevel[currentLevel].x, cameraPositionPerLevel[currentLevel].y, -10);
                levelObjects[currentLevel].SetActive(true);
                child.gameObject.GetComponent <SpriteRenderer>().enabled = true;
                overlayFog.GetComponent <SpriteRenderer>().enabled       = false;
                Debug.Log("Current Level is " + currentLevel);
                myUILevelText.text = "Level : " + (currentLevel + 1);
                //myUIStageText.text = "Stage : " + (currentStage + 1);
            }
        }
    }