예제 #1
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);
    }