コード例 #1
0
    // Update
    private void Update()
    {
        // Don't do anything if menu state is not the first state
        if (SCR_Menu.menuLoaded == false)
        {
            return;
        }

        float dt = Time.deltaTime;

        if (Input.GetMouseButton(0))
        {
            float touchX = Input.mousePosition.x * TOUCH_SCALE;
            float touchY = Input.mousePosition.y * TOUCH_SCALE;

            if (gameState == GameState.TALKING)
            {
                gameState = GameState.GRABBING;
                player.GetComponent <SCR_Player>().GoGrabTheBoss();
            }
            else if (gameState == GameState.PUNCHING)
            {
                if (SCR_Profile.showTutorial == 0 ||
                    tutorialStep == TutorialStep.AIM ||
                    tutorialStep == TutorialStep.PUNCH ||
                    tutorialStep == TutorialStep.CONTINUE)
                {
                    player.GetComponent <SCR_Player>().Aim(touchX, touchY + cameraHeight);
                }

                if (SCR_Profile.showTutorial == 1 && tutorialStep == TutorialStep.AIM)
                {
                    tutorialCounter += dt;
                    if (tutorialCounter > TUTORIAL_HOLD_DURATION)
                    {
                        TriggerTutorial(TutorialStep.PUNCH);
                    }
                }
            }
        }
        else
        {
            if (gameState == GameState.GRABBING)
            {
                if (player.GetComponent <SCR_Player>().IsGrabbingTheBoss())
                {
                    gameState = GameState.PUNCHING;
                    player.GetComponent <SCR_Player>().ThrowTheBoss();
                }
            }
            else if (gameState == GameState.PUNCHING)
            {
                player.GetComponent <SCR_Player>().PerformPunch();
            }
            tutorialCounter = 0;
        }

        /*
         * if (Input.GetMouseButtonUp(0) && gameState == GameState.BOSS_RUNNING) {
         *      if (boss.GetComponent<SCR_Boss>().IsRunning()) {
         *              SceneManager.LoadScene("GSMenu/SCN_Menu");
         *              SCR_Audio.PlayClickSound();
         *      }
         * }
         */
        if (gameState == GameState.PUNCHING)
        {
            cameraTarget = boss.GetComponent <SCR_Boss>().y - SCREEN_H + CAMERA_OFFSET_Y;
            if (cameraTarget > cameraHeight)
            {
                float deltaCamera = (cameraTarget - cameraHeight) * dt * CAMERA_SPEED_MULTIPLIER;
                SCR_LightBar.deltaCamera = deltaCamera;

                cameraHeight += deltaCamera;

                player.GetComponent <SCR_Player>().AddDeltaCameraToPlayer(deltaCamera);
                security.GetComponent <SCR_Security>().AddDeltaCameraToSecurity(deltaCamera);

                if (flyingObject != null)
                {
                    flyingObject.GetComponent <SCR_FlyingObject>().AddDeltaCameraToObject(deltaCamera);
                }

                if (powerUp != null)
                {
                    powerUp.GetComponent <SCR_PowerUp>().AddDeltaCameraToObject(deltaCamera);
                }
            }

            if (!breakFurniture)
            {
                if (boss.GetComponent <SCR_Boss>().y > FURNITURE_Y - SCR_Boss.BOSS_SIZE)
                {
                    SCR_Background.BreakFurniture(boss.GetComponent <SCR_Boss>().x, boss.GetComponent <SCR_Boss>().y, boss.GetComponent <SCR_Boss>().speedY);
                    breakFurniture = true;
                }
            }

            if (flyingObject == null)
            {
                if (SCR_Profile.showTutorial == 0)
                {
                    objectCounter += dt;
                    if (objectCounter >= objectSpawnTime - OBJECT_DANGER_BEFORE && !dangerShowed && cameraHeight > 100000)
                    {
                        ShowDanger();
                        dangerShowed = true;
                    }

                    if (objectCounter >= objectSpawnTime)
                    {
                        objectCounter   = 0;
                        objectSpawnTime = Random.Range(OBJECT_SPAWN_TIME_MIN, OBJECT_SPAWN_TIME_MAX);

                        dangerShowed = false;

                        if (cameraHeight > 400000)
                        {
                            flyingObject = SCR_Pool.GetFreeObject(PFB_FlyingObject[2]);
                        }
                        else if (cameraHeight > 250000)
                        {
                            flyingObject = SCR_Pool.GetFreeObject(PFB_FlyingObject[1]);
                        }
                        else if (cameraHeight > 100000)
                        {
                            flyingObject = SCR_Pool.GetFreeObject(PFB_FlyingObject[0]);
                        }

                        if (flyingObject != null)
                        {
                            float x = Random.Range(-(SCREEN_W - SCR_FlyingObject.OBJECT_SIZE) * 0.5f, (SCREEN_W - SCR_FlyingObject.OBJECT_SIZE) * 0.5f);
                            float y = cameraHeight + Random.Range(1.0f, 1.5f) * SCREEN_H;
                            flyingObject.GetComponent <SCR_FlyingObject>().Spawn(x, y);
                        }
                    }
                }
            }
            else
            {
                if (flyingObject.GetComponent <SCR_FlyingObject>().broken == false)
                {
                    if (SCR_Helper.DistanceBetweenTwoPoint(flyingObject.GetComponent <SCR_FlyingObject>().x, flyingObject.GetComponent <SCR_FlyingObject>().y, boss.GetComponent <SCR_Boss>().x, boss.GetComponent <SCR_Boss>().y) < (SCR_FlyingObject.OBJECT_SIZE + SCR_Boss.BOSS_SIZE) * 0.5f)
                    {
                        float bossAngle = SCR_Helper.AngleBetweenTwoPoint(flyingObject.GetComponent <SCR_FlyingObject>().x, flyingObject.GetComponent <SCR_FlyingObject>().y, boss.GetComponent <SCR_Boss>().x, boss.GetComponent <SCR_Boss>().y);
                        boss.GetComponent <SCR_Boss>().CrashIntoObject(bossAngle);
                        flyingObject.GetComponent <SCR_FlyingObject>().Break();

                        firstDrone = false;
                    }

                    else if (SCR_Helper.DistanceBetweenTwoPoint(flyingObject.GetComponent <SCR_FlyingObject>().x, flyingObject.GetComponent <SCR_FlyingObject>().y, player.GetComponent <SCR_Player>().x, player.GetComponent <SCR_Player>().y) < (SCR_FlyingObject.OBJECT_SIZE + SCR_Player.PLAYER_SIZE) * 0.5f)
                    {
                        flyingObject.GetComponent <SCR_FlyingObject>().Break();

                        firstDrone = false;
                    }
                }
            }

            if (powerUp == null || !powerUp.activeSelf)
            {
                if (SCR_Profile.showTutorial == 0)
                {
                    powerUpCounter += dt;
                    if (powerUpCounter >= powerUpSpawnTime)
                    {
                        powerUpCounter   = 0;
                        powerUpSpawnTime = Random.Range(POWER_UP_SPAWN_TIME_MIN, POWER_UP_SPAWN_TIME_MAX);

                        int choose = Random.Range(0, (int)PowerUpType.COUNT);
                        powerUp = SCR_Pool.GetFreeObject(PFB_PowerUp[choose]);
                        powerUp.GetComponent <SCR_PowerUp>().Spawn();
                    }
                }
            }
            else
            {
                float powerUpX = powerUp.GetComponent <SCR_PowerUp>().x;
                float powerUpY = powerUp.GetComponent <SCR_PowerUp>().y;
                float bossX    = boss.GetComponent <SCR_Boss>().x;
                float bossY    = boss.GetComponent <SCR_Boss>().y;
                float playerX  = player.GetComponent <SCR_Player>().x;
                float playerY  = player.GetComponent <SCR_Player>().y;

                float bossEdibleDistance      = (SCR_PowerUp.POWER_UP_SIZE + SCR_Boss.BOSS_SIZE) * 0.5f;
                float playerEdibleDistance    = (SCR_PowerUp.POWER_UP_SIZE + SCR_Player.PLAYER_SIZE) * 0.5f;
                float bossDistanceToPowerUp   = SCR_Helper.DistanceBetweenTwoPoint(powerUpX, powerUpY, bossX, bossY);
                float playerDistanceToPowerUp = SCR_Helper.DistanceBetweenTwoPoint(powerUpX, powerUpY, playerX, playerY);

                if (firstPizza)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        bossX += boss.GetComponent <SCR_Boss>().speedX *dt;
                        bossY += boss.GetComponent <SCR_Boss>().speedY *dt;
                        if (SCR_Helper.DistanceBetweenTwoPoint(powerUpX, powerUpY, bossX, bossY) <= bossEdibleDistance)
                        {
                            Time.timeScale = 0.01f;
                            firstPizza     = false;
                            break;
                        }

                        playerX += player.GetComponent <SCR_Player>().speedX *dt;
                        playerY += player.GetComponent <SCR_Player>().speedY *dt;
                        if (SCR_Helper.DistanceBetweenTwoPoint(powerUpX, powerUpY, playerX, playerY) <= playerEdibleDistance)
                        {
                            Time.timeScale = 0.01f;
                            firstPizza     = false;
                            break;
                        }
                    }
                }

                if (bossDistanceToPowerUp < bossEdibleDistance || playerDistanceToPowerUp < playerEdibleDistance)
                {
                    if (powerUp.GetComponent <SCR_PowerUp>().type == PowerUpType.PIZZA)
                    {
                        boss.GetComponent <SCR_Boss>().Enlarge();
                    }
                    else if (powerUp.GetComponent <SCR_PowerUp>().type == PowerUpType.BUBBLE)
                    {
                        boss.GetComponent <SCR_Boss>().Bubble();
                    }
                    else if (powerUp.GetComponent <SCR_PowerUp>().type == PowerUpType.MAGNET)
                    {
                        boss.GetComponent <SCR_Boss>().Magnet();
                    }

                    powerUp.SetActive(false);
                    powerUp = null;
                }
                else if (powerUpY <= cameraHeight - SCR_PowerUp.POWER_UP_SIZE)
                {
                    powerUp.SetActive(false);
                    powerUp = null;
                }
            }
        }
        else if (gameState == GameState.BOSS_FALLING)
        {
            float deltaCamera = -cameraHeight * dt * CAMERA_SPEED_MULTIPLIER;
            if (deltaCamera > -1)
            {
                deltaCamera = -1;
            }
            SCR_LightBar.deltaCamera = deltaCamera;

            cameraHeight += deltaCamera;

            player.GetComponent <SCR_Player>().TurnOffCrossHair();

            if (cameraHeight < CAMERA_ENDING_Y)
            {
                gameState = GameState.BOSS_RUNNING;
                player.GetComponent <SCR_Player>().ReAdjustY();
                boss.GetComponent <SCR_Boss>().ReAdjustY();
            }
        }
        else if (gameState == GameState.BOSS_RUNNING)
        {
            float deltaCamera = -cameraHeight * dt * CAMERA_SPEED_MULTIPLIER;
            if (deltaCamera > -1)
            {
                deltaCamera = -1;
            }
            cameraHeight += deltaCamera;
            if (cameraHeight < 0)
            {
                cameraHeight = 0;
            }
        }

        SCR_Background.SetCameraY(cameraHeight);

        if (cameraShakeTime > 0)
        {
            cameraShakeTime -= dt;
            Camera.main.transform.position = new Vector3(SCREEN_W * 0.5f + Random.Range(-CAMERA_SHAKE_AMOUNT, CAMERA_SHAKE_AMOUNT), SCREEN_H * 0.5f + cameraHeight + Random.Range(-CAMERA_SHAKE_AMOUNT, CAMERA_SHAKE_AMOUNT), Camera.main.transform.position.z);
        }
        else
        {
            Camera.main.transform.position = new Vector3(SCREEN_W * 0.5f, SCREEN_H * 0.5f + cameraHeight, Camera.main.transform.position.z);
        }

        if (comboTime > 0)
        {
            comboTime -= dt;
            if (comboTime <= 0)
            {
                comboTime  = 0;
                comboCount = 0;

                /*
                 * for (int i=1; i<imgCombo.Length; i++) {
                 *      imgCombo[i].SetActive (false);
                 * }
                 * imgCombo[0].SetActive (true);
                 */
            }
        }
        //imgClockContent.GetComponent<Image>().fillAmount = comboTime / COMBO_TIME;

        if (boss.GetComponent <SCR_Boss>().y * 0.01f - 3 > maxBossY)
        {
            maxBossY = (int)(boss.GetComponent <SCR_Boss>().y * 0.01f - 3);
            txtCurrentHeight.GetComponent <Text>().text = maxBossY.ToString();
        }

        if (SCR_Profile.showTutorial == 1)
        {
            if (tutorialStep != TutorialStep.AIM && Time.timeScale < 1)
            {
                Time.timeScale += dt * 2.0f;
                if (Time.timeScale > 1)
                {
                    Time.timeScale = 1;
                }
            }
        }
        else
        {
            if (Time.timeScale < 1)
            {
                Time.timeScale += dt * 3.0f;
                if (Time.timeScale > 1)
                {
                    Time.timeScale = 1;
                }
            }
        }

        if (flashWhiteAlpha > 0)
        {
            flashWhiteAlpha -= dt * 2.0f;
            if (flashWhiteAlpha < 0)
            {
                flashWhiteAlpha = 0;
            }

            Color color = pnlFlashWhite.GetComponent <Image>().color;
            color.a = flashWhiteAlpha;
            pnlFlashWhite.GetComponent <Image>().color = color;
        }

        if (SCR_Profile.showTutorial == 0)
        {
            if (tutorialAlpha > 0)
            {
                tutorialAlpha -= TUTORIAL_FADE_SPEED * dt;
                if (tutorialAlpha < 0)
                {
                    tutorialAlpha = 0;
                }
                Color color = txtTutorial.GetComponent <Text>().color;
                color.a = tutorialAlpha;
                txtTutorial.GetComponent <Text>().color = color;
            }
        }


        if (SCR_Profile.money - internalMoney > 1000)
        {
            internalMoney += 57;
        }
        else if (SCR_Profile.money - internalMoney > 100)
        {
            internalMoney += 13;
        }
        else if (SCR_Profile.money - internalMoney > 10)
        {
            internalMoney += 7;
        }
        else if (SCR_Profile.money - internalMoney > 0)
        {
            internalMoney += 1;
        }

        if (SCR_Profile.money - internalMoney < -1000)
        {
            internalMoney -= 57;
        }
        else if (SCR_Profile.money - internalMoney < -100)
        {
            internalMoney -= 13;
        }
        else if (SCR_Profile.money - internalMoney < -10)
        {
            internalMoney -= 7;
        }
        else if (SCR_Profile.money - internalMoney < 0)
        {
            internalMoney -= 1;
        }

        txtMoney.GetComponent <Text>().text = internalMoney.ToString();
    }
コード例 #2
0
    // ==================================================
    private void Update()
    {
        float dt = Time.deltaTime;

        if (SCR_Gameplay.instance.gameState == GameState.BOSS_FALLING)
        {
            dt = 0;
        }

        if (state == PlayerState.TRANSFORM)
        {
            trasnformCount += dt;
            if (trasnformCount >= PLAYER_TRANSFORM_TIME)
            {
                SwitchState(PlayerState.WALK);
            }

            if (trasnformCount >= PLAYER_TEAR_TIME && trasnformCount - dt < PLAYER_TEAR_TIME)
            {
                tearParticle.transform.position = new Vector3(transform.position.x, transform.position.y, tearParticle.transform.position.z);
                foreach (Transform child in tearParticle.transform)
                {
                    child.gameObject.SetActive(true);
                }
            }
        }
        else if (state == PlayerState.WALK || state == PlayerState.GRAB)
        {
            x += direction * PLAYER_WALK_SPEED * dt;
            if (x <= -(SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X))
            {
                x         = -(SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X);
                direction = 1;
            }
            else if (x >= (SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X))
            {
                x         = (SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X);
                direction = -1;
            }

            if (state == PlayerState.WALK)
            {
                if (bossScript.IsTalking())
                {
                    if (Mathf.Abs(x - bossScript.x) < PLAYER_GRAB_RANGE)
                    {
                        bossScript.Grabbed();
                        SCR_WaitMusic.FadeOut();
                        SCR_PunchMusic.FadeIn();
                        SwitchState(PlayerState.GRAB);
                        SCR_Gameplay.instance.TriggerTutorial(TutorialStep.THROW);
                    }
                }
            }
            if (state == PlayerState.GRAB)
            {
                bossScript.x         = x + direction * PLAYER_GRAB_RANGE;
                bossScript.y         = y + PLAYER_GRAB_HEIGHT;
                bossScript.direction = -direction;
            }

            if (SCR_Gameplay.instance.gameState == GameState.BOSS_FALLING || SCR_Gameplay.instance.gameState == GameState.BOSS_RUNNING)
            {
                SwitchState(PlayerState.WATCH);
            }
        }
        else if (state == PlayerState.CHARGE)
        {
            chargeCount += dt;
            if (chargeCount >= PLAYER_CHARGE_TIME && chargeCount - dt < PLAYER_CHARGE_TIME)
            {
                bossScript.Thrown();

                float particleX = (x + bossScript.x) * 0.5f;
                float particleY = (y + bossScript.y) * 0.5f;
                punchParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + particleX, particleY, punchParticle.transform.position.z);
                foreach (Transform child in punchParticle.transform)
                {
                    child.gameObject.SetActive(true);
                }
                Material shockMaterial = punchParticle.transform.Find("Shock").GetComponent <Renderer>().sharedMaterial;
                shockMaterial.SetColor("_TintColor", PUNCH_PARTICLE_COLORS[0]);

                if (SCR_Profile.showTutorial == 0)
                {
                    SCR_Gameplay.instance.ShowSecurityProgress();
                }
            }
            else if (chargeCount >= PLAYER_CHARGE_TIME + PLAYER_THROW_TIME)
            {
                SwitchState(PlayerState.WATCH);
                chargeCount = 0;
            }
        }
        else if (state == PlayerState.THROW)
        {
            chargeCount += dt;
            if (chargeCount >= PLAYER_THROW_TIME)
            {
                chargeCount = 0;
                SwitchState(PlayerState.WATCH);
            }
        }
        else if (state == PlayerState.FLY_UP || state == PlayerState.PUNCH || state == PlayerState.FLY_DOWN)
        {
            if (state == PlayerState.FLY_UP)
            {
                var distance = SCR_Helper.DistanceBetweenTwoPoint(x, y, bossScript.x, bossScript.y);
                if (distance <= PLAYER_PUNCH_RANGE * bossScript.currentScale.x / bossScript.originalScale.x)
                {
                    Punch(distance);
                    SwitchState(PlayerState.PUNCH);
                    speedY = 0;
                    trail.GetComponent <SCR_Trail>().TurnParticleOff();
                }
                else if (y > SCR_Gameplay.instance.cameraHeight + SCR_Gameplay.SCREEN_H)
                {
                    SwitchState(PlayerState.FLY_DOWN);
                    speedY = 0;
                    trail.GetComponent <SCR_Trail>().TurnParticleOff();
                }
            }
            else if (state == PlayerState.PUNCH)
            {
                speedY -= SCR_Gameplay.GRAVITY * dt;
                target.SetActive(false);
                punchCount -= dt;
                if (punchCount < 0)
                {
                    punchCount = 0;
                    SwitchState(PlayerState.FLY_DOWN);
                }
            }
            else if (state == PlayerState.FLY_DOWN)
            {
                speedY -= SCR_Gameplay.GRAVITY * dt;
                target.SetActive(false);
            }

            x += speedX * dt;
            y += speedY * dt;

            if (speedX < 0 && x <= -(SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X))
            {
                x         = -(SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X);
                speedX    = -speedX;
                direction = 1;
                Ricochet();
            }
            else if (speedX > 0 && x >= (SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X))
            {
                x         = (SCR_Gameplay.SCREEN_W * 0.5f - PLAYER_REVERSE_X);
                speedX    = -speedX;
                direction = -1;
                Ricochet();
            }

            if (state == PlayerState.FLY_UP)
            {
                trail.GetComponent <SCR_Trail>().MoveTo(x, y);
            }
            else if (state == PlayerState.FLY_DOWN)
            {
                if (y <= SCR_Gameplay.instance.cameraHeight - PLAYER_SIZE || y <= PLAYER_START_Y)
                {
                    y = PLAYER_START_Y;
                    SwitchState(PlayerState.LAND);

                    landCount = 0;
                    landParticle.SetActive(true);
                    landParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y + PLAYER_SMOKE_OFFSET_Y, landParticle.transform.position.z);
                }
            }
        }
        else if (state == PlayerState.LAND)
        {
            landCount += dt;
            if (landCount >= PLAYER_LAND_TIME)
            {
                SwitchState(PlayerState.WATCH);
            }
        }
        else if (state == PlayerState.WATCH)
        {
            if (bossScript.x < x)
            {
                direction = -1;
            }
            else
            {
                direction = 1;
            }
        }

        if (y <= SCR_Gameplay.instance.cameraHeight - PLAYER_SIZE)
        {
            marker.SetActive(true);
            marker.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, SCR_Gameplay.instance.cameraHeight, landParticle.transform.position.z);
        }
        else
        {
            marker.SetActive(false);
        }

        transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y, transform.position.z);
        transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * PLAYER_SCALE * (-direction), SCR_Gameplay.SCREEN_SCALE * PLAYER_SCALE, 1);

        float shadowScale = 1 - (y - PLAYER_START_Y) / PLAYER_SHADOW_DISTANCE;

        if (shadowScale < 0)
        {
            shadowScale = 0;
        }
        shadow.transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, shadow.transform.position.y, shadow.transform.position.z);
        shadow.transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * PLAYER_SHADOW_SCALE * shadowScale, SCR_Gameplay.SCREEN_SCALE * PLAYER_SHADOW_SCALE * shadowScale, 1);
    }
コード例 #3
0
    public void PerformPunch()
    {
        if (target.activeSelf)
        {
            targetX = currentAimX - SCR_Gameplay.SCREEN_W * 0.5f;
            targetY = currentAimY;

            if (SCR_Profile.showTutorial == 1)
            {
                SCR_Gameplay.instance.ShowSecurityProgress();
                if (SCR_Gameplay.instance.tutorialStep == TutorialStep.AIM)
                {
                    target.SetActive(false);
                    return;
                }
                if (SCR_Gameplay.instance.tutorialStep == TutorialStep.PUNCH)
                {
                    if (SCR_Helper.DistanceBetweenTwoPoint(targetX, targetY, bossScript.predictX, bossScript.predictY) > PLAYER_TUTORIAL_RANGE)
                    {
                        target.SetActive(false);
                        //return;
                    }
                }
            }


            y = SCR_Gameplay.instance.cameraHeight - PLAYER_SIZE;
            if (y < PLAYER_START_Y)
            {
                y = PLAYER_START_Y;
            }

            if (targetX >= x)
            {
                direction = 1;
            }
            else
            {
                direction = -1;
            }

            flyAngle = SCR_Helper.AngleBetweenTwoPoint(x, y, targetX, targetY);
            speedX   = PLAYER_FLY_SPEED * SCR_Helper.Sin(flyAngle);
            speedY   = PLAYER_FLY_SPEED * SCR_Helper.Cos(flyAngle);

            trail.GetComponent <SCR_Trail>().JumpTo(x, y);
            trail.GetComponent <SCR_Trail>().TurnParticleOn();

            target.SetActive(false);

            SwitchState(PlayerState.FLY_UP);
            SCR_Audio.PlayFlyUpSound();

            ricocheted = false;

            if (SCR_Profile.showTutorial == 1)
            {
                SCR_Gameplay.instance.TriggerTutorial(TutorialStep.FLY_UP);
                bossScript.HideTutorial();
            }
        }
        else
        {
            target.SetActive(false);
        }
    }
コード例 #4
0
    // ==================================================
    private void Update()
    {
        float dt = Time.deltaTime;

        if (state == SecurityState.STAND)
        {
        }
        else if (state == SecurityState.CHEER)
        {
        }
        else if (state == SecurityState.FLY_UP)
        {
            float flyAngle = SCR_Helper.AngleBetweenTwoPoint(x, y, bossScript.x, bossScript.y);
            speedX = SECURITY_SPEED * SCR_Helper.Sin(flyAngle);
            speedY = SECURITY_SPEED * SCR_Helper.Cos(flyAngle);

            var distance = SCR_Helper.DistanceBetweenTwoPoint(x, y, bossScript.x, bossScript.y);
            if (distance <= SECURITY_RANGE * bossScript.currentScale.x / bossScript.originalScale.x)
            {
                speedY = 0;
                trail.GetComponent <SCR_Trail>().TurnParticleOff();
                Punch();
                SwitchState(SecurityState.FLY_DOWN);
            }

            if (laughDelay > 0)
            {
                laughDelay -= dt;
                if (laughDelay <= 0)
                {
                    SCR_Audio.PlaySecurityLaughSound();
                }
            }
        }
        else if (state == SecurityState.FLY_DOWN)
        {
            SwitchState(SecurityState.FLY_DOWN);
            speedY -= SCR_Gameplay.GRAVITY * dt;
        }

        x += speedX * dt;
        y += speedY * dt;

        if (state == SecurityState.FLY_UP)
        {
            trail.GetComponent <SCR_Trail>().MoveTo(x, y);
        }
        else if (state == SecurityState.FLY_DOWN)
        {
            if (speedX < 0 && x <= -(SCR_Gameplay.SCREEN_W * 0.5f - SECURITY_SIZE * 0.5f))
            {
                x      = -(SCR_Gameplay.SCREEN_W * 0.5f - SECURITY_SIZE * 0.5f);
                speedX = -speedX;
            }
            else if (speedX > 0 && x >= (SCR_Gameplay.SCREEN_W * 0.5f - SECURITY_SIZE * 0.5f))
            {
                x      = (SCR_Gameplay.SCREEN_W * 0.5f - SECURITY_SIZE * 0.5f);
                speedX = -speedX;
            }
            if (y <= SCR_Gameplay.instance.cameraHeight - SECURITY_SIZE || y <= SECURITY_START_Y)
            {
                y      = SECURITY_START_Y;
                speedX = 0;
                speedY = 0;
                SwitchState(SecurityState.STAND);

                landParticle.SetActive(true);
                landParticle.transform.position = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y + SECURITY_SMOKE_OFFSET_Y, landParticle.transform.position.z);
            }
        }

        transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, y, transform.position.z);
        transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE * direction, SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE, SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE);

        float shadowScale = 1 - (y - SECURITY_START_Y) / SECURITY_SHADOW_DISTANCE;

        if (shadowScale < 0)
        {
            shadowScale = 0;
        }
        shadow.transform.position   = new Vector3(SCR_Gameplay.SCREEN_W * 0.5f + x, shadow.transform.position.y, shadow.transform.position.z);
        shadow.transform.localScale = new Vector3(SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE * shadowScale * (-direction), SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE * shadowScale, SCR_Gameplay.SCREEN_SCALE * SECURITY_SCALE);
    }