示例#1
0
    void FixedUpdate()
    {
        float vertical   = Input.GetAxis("Vertical");
        float horizontal = Input.GetAxis("Horizontal");

        if (vertical != 0)
        {
            Walk();
        }
        else
        {
            Idle();
        }

        Vector3 vel;

        if (animalType == animalTypes.BIRD)
        {
            vel = transform.forward * vertical * speed_bird;
        }
        else
        {
            vel = transform.forward * vertical * speed;
        }

        vel.y       = rb.velocity.y;
        rb.velocity = vel;

        //Avanzar con fuerza de empuje:
        //rb.AddForce (transform.forward * vertical * speed);

        transform.Rotate(Vector3.up * horizontal * speedRotation);
        transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y, 0);

        if (Input.GetButtonDown("ChangeWeapon"))
        {
            weapons.ChangeWeapon();
        }
        if (Input.GetButtonDown("Fire1"))
        {
            characterAttack.Attack();
        }
        if (animalType == animalTypes.BIRD)
        {
            if (Input.GetButton("Jump"))
            {
                Vector3 v = rb.velocity;
                v.y         = 0;
                rb.velocity = v;

                Vector3 pos = transform.localPosition;
                pos.y += flyForce;
                transform.localPosition = pos;
                print("sube" + pos.y);
            }
        }
        else
        {
            if (Input.GetButtonDown("Jump"))
            {
                if (rb.velocity.y == 0 || jumpCount <= 1)
                {
                    Vector3 v = rb.velocity;
                    v.y         = 0;
                    rb.velocity = v;
                    rb.AddForce(Vector3.up * jumpForce);
                    jumpCount++;
                }
            }
            else if (rb.velocity.y == 0)
            {
                jumpCount = 0;
            }
        }
    }