示例#1
0
    public void Move(float move, bool jump)
    {
        //if (move == 0) return;
        if (Mathf.Abs(move) > 0)
        {
            Quaternion rot  = transform.rotation;
            var        sign = Mathf.Sign(move);
            transform.rotation = Quaternion.Euler(rot.x, sign == 1 ? 0 : 180, rot.z);
            if (sign != prevSign)
            {
                prevSign = sign;
                charaProvider.ChangeDirection();
            }
        }

        charaProvider.m_rigidbody2D.velocity = new Vector2(move * maxSpeed, charaProvider.m_rigidbody2D.velocity.y);

        /*charaProvider.m_rigidbody2D.AddForce(transform.right * move);
         * var vec = charaProvider.m_rigidbody2D.velocity;
         * if (Mathf.Abs(vec.x) > maxSpeed) {
         *  vec.x = vec.x < 0 ? -maxSpeed : maxSpeed;
         *  charaProvider.m_rigidbody2D.velocity = vec;
         * }*/

        //transform.Translate(transform.right * move * maxSpeed);
        //JUMP
    }