示例#1
0
    // check situation by tutorial index
    private void Update()
    {
        if (increaseVolume)
        {
            soundTimer += Time.deltaTime;
            bgm.volume  = 0.05f * deltaTime(soundTimer, 1f) + 0.05f;
        }


        if (GameManager.instance.isTutorial)
        {
            // tutorial for Koto Tower
            if (tutorialIdx == 1)
            {
                if (!kotoTowerGeneratorTruckButton.getShowKotoTower())
                {
                    timer += Time.deltaTime;
                }
                else
                {
                    timer = 0;
                }

                if (timer >= 0.5f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for generator
            if (tutorialIdx == 3)
            {
                if (!kotoTowerGeneratorTruckButton.getShowGenerator())
                {
                    timer += Time.deltaTime;
                }
                else
                {
                    timer = 0;
                }

                if (timer >= 0.5f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for char charge
            if (tutorialIdx == 5)
            {
                if (QuestionManager.isSendingTruck)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 1f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for path selection
            if (tutorialIdx == 7)
            {
                if (truck.getTruckStatus() == TruckStatus.WAITING)
                {
                    nextAndOpen();
                }
            }

            // tutorial for answer the right one
            if (tutorialIdx == 9)
            {
                if (GameManager.instance.totalAnsweredQuestion == 1)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 0.3f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for char charge power
            if (tutorialIdx == 11)
            {
                if (QuestionManager.isSendingTruck)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 0.3f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for char Tower
            if (tutorialIdx == 13)
            {
                if (GameManager.instance.totalAnsweredQuestion == 2)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 0.2f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for enemy and Koto Tower
            if (tutorialIdx == 15)
            {
                answer.SetActive(false);
                question.SetActive(false);

                // show this tutorial when in building mode
                tutorialList[tutorialIdx].activateGameObject[0].SetActive(false);
                tutorialList[tutorialIdx].activateGameObject[1].SetActive(false);
                tutorialList[tutorialIdx].activateGameObject[2].SetActive(true);

                // check if the player has spawned 2 towers
                if (tower.childCount > 1 && !forTutor)
                {
                    TowerBehaviour towerBehaveOne = tower.GetChild(0).GetComponent <TowerBehaviour>();
                    TowerBehaviour towerBehaveTwo = tower.GetChild(1).GetComponent <TowerBehaviour>();
                    if (towerBehaveOne.getIsActive() && towerBehaveTwo.getIsActive())
                    {
                        forTutor = true;
                    }
                }

                if (GameManager.instance.isSelectTower)
                {
                    tutorialList[tutorialIdx].activateGameObject[0].SetActive(true);
                    tutorialList[tutorialIdx].activateGameObject[1].SetActive(true);
                    tutorialList[tutorialIdx].activateGameObject[2].SetActive(false);
                }

                if (forTutor)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 1f)
                {
                    nextAndOpen();
                    answer.SetActive(true);
                    question.SetActive(true);
                    forTutor = false;
                    timer    = 0;
                }
            }

            // tutorial for enemy
            if (tutorialIdx == 17)
            {
                if (GameManager.instance.totalAnsweredQuestion == 3)
                {
                    timer += Time.deltaTime;
                }

                if (timer >= 0.3f)
                {
                    nextAndOpen();
                    timer = 0;
                }
            }

            // tutorial for trap
            if (tutorialIdx == 19)
            {
                if (changeMoney)
                {
                    GameManager.instance.money       += 100f;
                    GameManager.instance.moneyChanged = true;
                    changeMoney = false;
                }
                answer.SetActive(false);
                question.SetActive(false);
                tutorialList[tutorialIdx].activateGameObject[2].SetActive(false);
                tutorialList[tutorialIdx].activateGameObject[3].SetActive(false);
                tutorialList[tutorialIdx].activateGameObject[4].SetActive(true);

                // check if the player has spawned a trap
                if (trap.childCount > 0 && !forTutor)
                {
                    TrapsBehaviour trapBehave = trap.GetChild(0).GetComponent <TrapsBehaviour>();
                    if (trapBehave.getIsActive())
                    {
                        forTutor = true;
                    }
                }

                if (forTutor)
                {
                    timer += Time.deltaTime;
                }

                if (GameManager.instance.isSelectTrap)
                {
                    tutorialList[tutorialIdx].activateGameObject[2].SetActive(true);
                    tutorialList[tutorialIdx].activateGameObject[3].SetActive(true);
                    tutorialList[tutorialIdx].activateGameObject[4].SetActive(false);
                }

                if (timer >= 4f)
                {
                    nextAndOpen();
                    answer.SetActive(true);
                    question.SetActive(true);
                    forTutor = false;
                    timer    = 0;
                }
            }

            // tutorial for end tutorial
            if (tutorialIdx == 21)
            {
                timer += Time.deltaTime;

                if (timer > 4f)
                {
                    nextAndWait();
                }
            }
        }
    }
示例#2
0
    // Update is called once per frame after normal update
    void Update()
    {
        if (GameManager.instance.isPaused)
        {
            cancel();
        }

        // for touch
        if (Input.touchCount > 0 && GameManager.instance.isSelectTrap && !isReadyToSpawn && !OtherMethod.onUiPressed(Input.GetTouch(0).position))
        {
            Touch touch = Input.GetTouch(0);

            // If it is the first time to build then make the trap
            if (!isReadyToBuild && !OtherMethod.onUiPressed(touch.position))
            {
                switch (GameManager.instance.selectedTrap)
                {
                case 0:
                    currentTrap     = Instantiate(trapBomb, this.transform);
                    currentTrapType = TrapType.BOMB_TRAP;
                    break;

                case 1:
                    currentTrap     = Instantiate(trapTime, this.transform);
                    currentTrapType = TrapType.TIME_TRAP;
                    break;

                case 2:
                    currentTrap     = Instantiate(trapFreeze, this.transform);
                    currentTrapType = TrapType.FREEZE_TRAP;
                    break;

                default:
                    currentTrap     = Instantiate(trapBomb, this.transform);
                    currentTrapType = TrapType.BOMB_TRAP;
                    break;
                }

                currentTrap.SetActive(false);
                SpriteRenderer renderer = currentTrap.GetComponent <SpriteRenderer>();
                renderer.color = new Color(1, 1, 1, 150f / 256f);
                isReadyToBuild = true;
            }

            if (touch.phase == TouchPhase.Began && !OtherMethod.onUiPressed(touch.position))
            {
                Vector2 touchPosition;
                touchPosition = mainCamera.ScreenToWorldPoint(touch.position);

                // checking if the place is open field
                int x, y;
                GridCustom.getXYFromPosition(touchPosition, out x, out y);

                x += GridCustom.offsetX;
                y += GridCustom.offsetY;

                if (GridCustom.cells[x, y].cellContent == CellContent.PATH)
                {
                    currentTrap.SetActive(true);
                    isReadyToSpawn = true;
                    canSpawn       = false;
                    currentTrap.transform.position = new Vector3(touch.position.x, touch.position.y, 0);
                }
            }
        }

        if (Input.touchCount > 0 && isReadyToBuild && isReadyToSpawn && !OtherMethod.onUiPressed(Input.GetTouch(0).position))
        {
            Touch   touch = Input.GetTouch(0);
            Vector2 touchPosition;
            touchPosition = mainCamera.ScreenToWorldPoint(touch.position);

            int x, y;
            GridCustom.getXYFromPosition(touchPosition, out x, out y);

            x += GridCustom.offsetX;
            y += GridCustom.offsetY;
            // if the player touch the area again then spawn the trap
            if (touch.phase == TouchPhase.Ended && GameManager.instance.isSelectTrap)
            {
                if (isReadyToSpawn && isReadyToBuild)
                {
                    canSpawn = true;
                }
                else if (canSpawn)
                {
                    // change the color
                    SpriteRenderer renderer = currentTrap.GetComponent <SpriteRenderer>();
                    renderer.color = new Color(1, 1, 1, 1);

                    // activate it
                    TrapsBehaviour trap = currentTrap.GetComponent <TrapsBehaviour>();
                    trap.activate();

                    // pay the trap
                    GameManager.instance.pay(currentTrapType);
                    trapButton.disableButton(GameManager.instance.selectedTrap);

                    // reset variable
                    currentTrap     = null;
                    currentTrapType = TrapType.BOMB_TRAP;
                    isReadyToBuild  = false;
                    isReadyToSpawn  = false;
                    canSpawn        = false;
                    desc.gameObject.SetActive(false);
                    GameEvents.current.TowerOrTrapBuild();
                    if (GameManager.instance.gameStart)
                    {
                        generator.StartCoroutine(generator.openGenerator());
                        kotoTower.StartCoroutine(kotoTower.openKotoTower());
                    }
                    return;
                }
            }
            else if (touch.phase == TouchPhase.Began && Vector3.Distance(currentTrap.transform.position, new Vector3(touchPosition.x, touchPosition.y, 0f)) > 0.5f)
            {
                isReadyToSpawn = false;
                canSpawn       = false;
            }
        }

        // for mouse (debug)
        if (Input.GetMouseButton(0) && GameManager.instance.isSelectTrap && !OtherMethod.onUiPressed(Input.mousePosition))
        {
            // If it is the first time to build then make the trap
            if (!isReadyToBuild)
            {
                switch (GameManager.instance.selectedTrap)
                {
                case 0:
                    currentTrap     = Instantiate(trapBomb, this.transform);
                    currentTrapType = TrapType.BOMB_TRAP;
                    break;

                case 1:
                    currentTrap     = Instantiate(trapTime, this.transform);
                    currentTrapType = TrapType.TIME_TRAP;
                    break;

                case 2:
                    currentTrap     = Instantiate(trapFreeze, this.transform);
                    currentTrapType = TrapType.FREEZE_TRAP;
                    break;

                default:
                    currentTrap     = Instantiate(trapBomb, this.transform);
                    currentTrapType = TrapType.BOMB_TRAP;
                    break;
                }

                currentTrap.SetActive(false);
                SpriteRenderer renderer = currentTrap.GetComponent <SpriteRenderer>();
                renderer.color = new Color(1, 1, 1, 150f / 256f);
                isReadyToBuild = true;
            }

            Vector2 touchPosition;
            touchPosition = mainCamera.ScreenToWorldPoint(Input.mousePosition);

            // checking if the place is open field
            int x, y;
            GridCustom.getXYFromPosition(touchPosition, out x, out y);

            x += GridCustom.offsetX;
            y += GridCustom.offsetY;

            if (Vector3.Distance(currentTrap.transform.position, touchPosition) > 0.5f)
            {
                isReadyToSpawn = false;
            }

            if (GridCustom.cells[x, y].cellContent == CellContent.PATH && !isReadyToSpawn)
            {
                currentTrap.SetActive(true);
                currentTrap.transform.position = new Vector3(touchPosition.x, touchPosition.y, -0);
            }
        }

        // if the player touch the area again then spawn the trap, if its the first time then just be ready to spawn
        if (Input.GetMouseButtonUp(0) && GameManager.instance.isSelectTrap && !OtherMethod.onUiPressed(Input.mousePosition))
        {
            if (!isReadyToSpawn && isReadyToBuild)
            {
                isReadyToSpawn = true;
            }
            else if (isReadyToBuild)
            {
                // change the color
                SpriteRenderer renderer = currentTrap.GetComponent <SpriteRenderer>();
                renderer.color = new Color(1, 1, 1, 1);

                // activate it
                TrapsBehaviour trap = currentTrap.GetComponent <TrapsBehaviour>();
                trap.activate();

                // pay the trap
                GameManager.instance.pay(currentTrapType);
                trapButton.disableButton(GameManager.instance.selectedTrap);

                // reset variable
                currentTrap     = null;
                currentTrapType = TrapType.BOMB_TRAP;
                isReadyToBuild  = false;
                isReadyToSpawn  = false;
                desc.gameObject.SetActive(false);
                GameEvents.current.TowerOrTrapBuild();
                if (GameManager.instance.gameStart)
                {
                    generator.StartCoroutine(generator.openGenerator());
                    kotoTower.StartCoroutine(kotoTower.openKotoTower());
                }
                return;
            }
        }
    }