Esempio n. 1
0
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.LeftArrow) || (MyStick.isClick && MyStick.Degree > 180f))
        {
            if (!LeanTween.isTweening(gameObject))
            {
                if (isGrounded())
                {
                    anim.Play("Walk");
                }
                else
                {
                    anim.Play("Idle");
                }

                if (dir != Direction.LEFT)
                {
                    LeanTween.rotateAroundLocal(gameObject, Vector3.up, 180f, 0.3f).setOnComplete(TurnLeft);
                }
                else
                {
                    transform.Translate(Vector3.forward * speed * Time.deltaTime);
                }
                isMoving = true;
            }
        }
        else if (Input.GetKey(KeyCode.RightArrow) || (MyStick.isClick && MyStick.Degree <= 180f))
        {
            if (!LeanTween.isTweening(gameObject))
            {
                if (isGrounded())
                {
                    anim.Play("Walk");
                }
                else
                {
                    anim.Play("Idle");
                }

                if (dir != Direction.RIGHT)
                {
                    LeanTween.rotateAroundLocal(gameObject, Vector3.up, -180f, 0.3f).setOnComplete(TurnRight);
                }
                else
                {
                    transform.Translate(Vector3.forward * speed * Time.deltaTime);
                }
                isMoving = true;
            }
        }
        else
        {
            anim.Play("Idle");
            isMoving = false;
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            RightArm.Rotate(Vector3.back * 200f * Time.deltaTime);
            LeftArm.Rotate(Vector3.back * 200f * Time.deltaTime);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            RightArm.Rotate(Vector3.forward * 200f * Time.deltaTime);
            LeftArm.Rotate(Vector3.forward * 200f * Time.deltaTime);
        }

        if (MyStick.isClick)
        {
            if (dir == Direction.RIGHT)
            {
                RightArm.localRotation = Quaternion.Euler(new Vector3(0f, 90f, MyStick.Degree - 90f));
                LeftArm.localRotation  = Quaternion.Euler(new Vector3(0f, 90f, MyStick.Degree + 90f));
            }
            else
            {
                RightArm.localRotation = Quaternion.Euler(new Vector3(0f, 90f, 270f - MyStick.Degree));
                LeftArm.localRotation  = Quaternion.Euler(new Vector3(0f, 90f, 90f - MyStick.Degree));
            }
        }

        if (Input.GetKey(KeyCode.Z) || Bbutton.isClick)
        {
            rigidbody.constantForce.force = Vector3.zero;
            if (rigidbody.velocity.y < 4f)
            {
                rigidbody.AddRelativeForce(Vector3.up * 20f);
            }

            if (!Boost.loop)
            {
                Boost.Play();
                Boost.loop = true;
            }
            isMoving = true;
        }
        else
        {
            rigidbody.constantForce.force = new Vector3(0f, -10f, 0f);
            Boost.loop = false;
        }

        if (Input.GetKey(KeyCode.X) || Abutton.isClick)
        {
            if (!audio.isPlaying)
            {
                audio.Play();
                StartCoroutine("LightControl");
            }
            RightMuzzle.emissionRate = LeftMuzzle.emissionRate = 10;
            RightFire.emissionRate   = LeftFire.emissionRate = 30;
        }
        else
        {
            audio.Stop();
            RightMuzzle.emissionRate = RightFire.emissionRate = LeftMuzzle.emissionRate = LeftFire.emissionRate = 0;
            LeftLight.intensity      = RightLight.intensity = 0f;
            StopCoroutine("LightControl");
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchMissile();
        }
        rigidbody.velocity = new Vector3(0f, rigidbody.velocity.y, 0f);
    }
    void FixedUpdate()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        var horizontal = Input.GetAxis("Horizontal");

        if (horizontal < 0)
        {
            if (!LeanTween.isTweening(gameObject))
            {
                if (isGrounded())
                {
                    anim.Play("Walk");
                }
                else
                {
                    anim.Play("Idle");
                }

                if (dir != Direction.LEFT)
                {
                    LeanTween.rotateAroundLocal(gameObject, Vector3.up, 180f, 0.3f).setOnComplete(TurnLeft);
                }
                else
                {
                    transform.Translate(Vector3.forward * speed * Time.deltaTime);
                }

                isMoving = true;
            }
        }
        else if (horizontal > 0)
        {
            if (!LeanTween.isTweening(gameObject))
            {
                if (isGrounded())
                {
                    anim.Play("Walk");
                }
                else
                {
                    anim.Play("Idle");
                }

                if (dir != Direction.RIGHT)
                {
                    LeanTween.rotateAroundLocal(gameObject, Vector3.up, -180f, 0.3f).setOnComplete(TurnRight);
                }
                else
                {
                    transform.Translate(Vector3.forward * speed * Time.deltaTime);
                }

                isMoving = true;
            }
        }
        else
        {
            anim.Play("Idle");
            isMoving = false;
        }

        var vertical = Input.GetAxis("Vertical");

        if (vertical > 0)
        {
            RightArm.Rotate(Vector3.back * 200f * Time.deltaTime);
            LeftArm.Rotate(Vector3.back * 200f * Time.deltaTime);
        }
        else if (vertical < 0)
        {
            RightArm.Rotate(Vector3.forward * 200f * Time.deltaTime);
            LeftArm.Rotate(Vector3.forward * 200f * Time.deltaTime);
        }

        if (MyStick.isClick)
        {
            if (dir == Direction.RIGHT)
            {
                RightArm.localRotation = Quaternion.Euler(new Vector3(0f, 90f, MyStick.Degree - 90f));
                LeftArm.localRotation  = Quaternion.Euler(new Vector3(0f, 90f, MyStick.Degree + 90f));
            }
            else
            {
                RightArm.localRotation = Quaternion.Euler(new Vector3(0f, 90f, 270f - MyStick.Degree));
                LeftArm.localRotation  = Quaternion.Euler(new Vector3(0f, 90f, 90f - MyStick.Degree));
            }
        }

        if (Input.GetKey(KeyCode.Z) || Bbutton.isClick)
        {
            GetComponent <Rigidbody>().GetComponent <ConstantForce>().force = Vector3.zero;
            if (GetComponent <Rigidbody>().velocity.y < 4f)
            {
                GetComponent <Rigidbody>().AddRelativeForce(Vector3.up * 20f);
            }

            if (!Boost.loop)
            {
                Boost.Play();
                Boost.loop = true;
            }

            isMoving = true;
        }
        else
        {
            GetComponent <Rigidbody>().GetComponent <ConstantForce>().force = new Vector3(0f, -10f, 0f);
            Boost.loop = false;
        }

        if (Input.GetKey(KeyCode.X) || Abutton.isClick)
        {
            if (!GetComponent <AudioSource>().isPlaying)
            {
                GetComponent <AudioSource>().Play();
                StartCoroutine("LightControl");
            }

            RightMuzzle.emissionRate = LeftMuzzle.emissionRate = 10;
            RightFire.emissionRate   = LeftFire.emissionRate = 30;
        }
        else
        {
            GetComponent <AudioSource>().Stop();
            RightMuzzle.emissionRate = RightFire.emissionRate = LeftMuzzle.emissionRate = LeftFire.emissionRate = 0;
            LeftLight.intensity      = RightLight.intensity = 0f;
            StopCoroutine("LightControl");
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchMissile();
        }

        GetComponent <Rigidbody>().velocity = new Vector3(0f, GetComponent <Rigidbody>().velocity.y, 0f);
    }