示例#1
0
    public void setDirection(playerDirection newDirection)
    {
        if(newDirection == playerDirection.left)
        {

            this.gameObject.transform.localScale = new Vector3(1.0f,-1.0f,1.0f);
        }
        else if(newDirection == playerDirection.right)
        {
                this.gameObject.transform.localScale = new Vector3(-1.0f,-1.0f,1.0f);
        }
    }
示例#2
0
    private void FixedUpdate() //it have to be in fixedupdate
    {
        move = new Vector2(horizontal, vertical);
        move = move.normalized;
        if (move.x > 0)
        {
            transform.eulerAngles = new Vector3(0, 0, 0);
            _direction            = playerDirection.right;
        }
        else if (move.x < 0)
        {
            transform.eulerAngles = new Vector3(180, 0, -180);
            _direction            = playerDirection.left;
        }
        if (move.y > 0)
        {
            transform.eulerAngles = new Vector3(0, 0, 90);
            _direction            = playerDirection.up;
        }
        else if (move.y < 0)
        {
            transform.eulerAngles = new Vector3(0, 0, -90);
            _direction            = playerDirection.down;
        }

        if (move.x != 0 && move.y != 0)
        {
            if (move.x > 0)
            {
                if (move.y > 0)
                {
                    _direction = playerDirection.rightUp;
                }
                else
                {
                    _direction = playerDirection.rightDown;
                }
            }
            else
            {
                if (move.y > 0)
                {
                    _direction = playerDirection.leftUp;
                }
                else
                {
                    _direction = playerDirection.leftDown;
                }
            }
        }
        _rigidbody.velocity = Time.deltaTime * move * runSpeed;
    }