示例#1
0
    void Update()
    {
        if (state != State.Platform)
        {
            if (sprite.flipX)
            {
                autoLook.lightsLeft();
            }
            else
            {
                autoLook.lightsRight();
            }
        }

        switch (state)
        {
        case State.Auto:
            //inputEnabled = false;
            defaultCam    = mainCam;
            autoLook.isOn = true;
            break;

        case State.Rage:

            break;

        case State.Controlled:
            //inputEnabled = true;
            autoLook.isOn = false;
            movement      = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
            if (((movement.x < 0 && !sprite.flipX) || (movement.x > 0 && sprite.flipX)))
            {
                sprite.flipX = !sprite.flipX;
            }
            if (inputEnabled && Input.GetButtonDown("ChangePawn") && canChangePawn)
            {
                mainScript.ChangePawn(1);
                state = State.Auto;
                EnableFollowing();
            }
            if (inputEnabled && Input.GetButtonDown("Fire1") && canPlatform)
            {
                AudioManager.instance.PlaySound(sounds[0], transform.position, 0.5f);
                inputEnabled = false;
                StartCoroutine(WaitForIn());
                state = State.Platform;
                animator.SetLayerWeight(1, 0);
                animator.SetBool("isPlatform", true);
                bCollider.enabled = true;
                rb2D.bodyType     = RigidbodyType2D.Static;
                for (int i = 0; i < lights.Length; i++)
                {
                    lights[i].color = Color.yellow;
                    if (sprite.flipX)
                    {
                        lights[0].gameObject.transform.localPosition = new Vector3(-0.163f, 0.08f, -0.03f);
                        lights[1].gameObject.transform.localPosition = new Vector3(0.082f, 0.08f, -0.03f);
                    }
                    else
                    {
                        lights[0].gameObject.transform.localPosition = new Vector3(-0.08f, 0.08f, -0.03f);
                        lights[1].gameObject.transform.localPosition = new Vector3(0.16f, 0.08f, -0.03f);
                    }
                }
            }
            break;

        case State.Platform:
            if ((inputEnabled && (Input.GetButtonDown("Fire1") || Input.GetButtonDown("Horizontal") || Input.GetButtonDown("Vertical"))) || reset)
            {
                AudioManager.instance.PlaySound(sounds[1], transform.position, 0.3f);
                animator.SetBool("isPlatform", false);
                inputEnabled = false;

                StartCoroutine(WaitForAnim());
            }
            if (inputEnabled && Input.GetButtonDown("ChangePawn"))
            {
                mainScript.ChangePawn(1);
                inputEnabled = false;
            }
            if (Vector3.Distance(transform.position, mainScript.playerPawn.transform.position) > distanceToReset && !playingCoroutine)
            {
                AudioManager.instance.PlaySound(sounds[1], transform.position, 0.5f);
                reset                  = true;
                inputEnabled           = false;
                bCollider.enabled      = false;
                circleCollider.enabled = false;
            }

            break;
        }
    }