예제 #1
0
파일: Seyana.cs 프로젝트: Musasin/Seyana
    // Update is called once per frame
    void Update()
    {
        if (talk.GetState() == Talk.State.RESULT)
        {
            sr.color = new Color(1, 1, 1);
        }

        if (talk.GetState() != Talk.State.TALK_A && talk.GetState() != Talk.State.TALK_D)
        {
            voiceTime += Time.deltaTime;

            if (voiceTime > 4)
            {
                voiceTime = 0;
                PlayVoice();
            }
        }

        if (talk.GetState() == Talk.State.TALK_B)
        {
            if (talk.GetMaxSeyana() == gameObject)
            {
                return;
            }
            if (talk.GetMaxScale() == scale && talk.GetMaxSeyana() == null)
            {
                rb.velocity        = Vector2.zero;
                transform.position = new Vector2(0, 1.0f);
                talk.SetMaxSeyana(gameObject);
                voiceTime = 0;
                PlayVoice();
            }
            else
            {
                Destroy(gameObject);
            }
        }
        if (talk.GetState() == Talk.State.TALK_C || talk.GetState() == Talk.State.TALK_D)
        {
            moveTime += Time.deltaTime;
            if (moveTime > 0.05f)
            {
                float movePower = (movementX + movementY) / 1000 * (isPosRight ? 1 : -1);
                transform.position = new Vector2(movePower, 1.0f);
                isPosRight         = !isPosRight;
                moveTime           = 0;

                if (talk.GetState() == Talk.State.TALK_D)
                {
                    float randR = Random.Range(0.2f, 1.0f);
                    float randG = Random.Range(0.2f, 1.0f);
                    float randB = Random.Range(0.2f, 1.0f);
                    sr.color = new Color(randR, randG, randB);
                }
            }
        }
        if (talk.GetState() == Talk.State.LIGHT || talk.GetState() == Talk.State.TALK_D)
        {
            scaleTime += Time.deltaTime;
            if (scaleTime > 0.5f)
            {
                scaleTime = 0;
            }
            transform.localScale = new Vector2(scale * 1.5f - (scale * scaleTime), scale * 1.5f - (scale * scaleTime));
            sr.color             = new Color(sr.color.r, sr.color.g, sr.color.b, scaleTime * 2.0f);
        }
        if (talk.GetState() == Talk.State.CONNECT || talk.GetState() == Talk.State.SHAKE)
        {
            if (isGrip)
            {
                if (Input.GetMouseButtonUp(0))
                {
                    AudioManager.Instance.PlaySE("petyo");
                    isGrip = false;
                }
                else
                {
                    var screenPos = Input.mousePosition;
                    screenPos.z = Mathf.Abs(mainCamera.transform.position.z);
                    if (screenPos.x < 0 || screenPos.x > Screen.width || screenPos.y < 0 || screenPos.y > Screen.height)
                    {
                        AudioManager.Instance.PlaySE("petyo");
                        isGrip = false;
                        return;
                    }

                    var worldPos = mainCamera.ScreenToWorldPoint(screenPos);

                    if (talk.GetState() == Talk.State.SHAKE)
                    {
                        movementX += Mathf.Abs(transform.position.x - worldPos.x) - Time.deltaTime * 5;
                        movementY += Mathf.Abs(transform.position.y - worldPos.y) - Time.deltaTime * 5;
                        movementX  = Mathf.Max(movementX, 0);
                        movementY  = Mathf.Max(movementY, 0);
                        talk.SetRedPower(movementX);
                        talk.SetBluePower(movementY);

                        soundMovementSum += Mathf.Abs(worldPos.x - transform.position.x) + Mathf.Abs(worldPos.y - transform.position.y);
                        if (soundMovementSum > 30)
                        {
                            AudioManager.Instance.PlaySE("buon");
                            soundMovementSum = 0;
                        }
                    }

                    transform.position = worldPos;
                }
            }
            else if (talk.GetState() == Talk.State.CONNECT)
            {
                rb.velocity          = new Vector2(velocityX * (isRight ? 1 : -1), rb.velocity.y);
                transform.localScale = new Vector2(isRight ? -scale : scale, scale);
            }
        }
    }