コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 _inputDirection = m_controls.MainControls.Movement.ReadValue <Vector2>();

        if (m_rb.velocity.x == 0 && m_rb.velocity.z == 0 && m_maxSpeed > m_startMaxSpeed)
        {
            m_maxSpeed = m_startMaxSpeed * 1;
        }
        Movement(_inputDirection);
        if (_inputDirection.x != 0 || _inputDirection.y != 0)
        {
            if (!isMoving)
            {
                isMoving = true;
                onStartMovement.Invoke();
            }
        }
        else if (_inputDirection.x == 0 || _inputDirection.y == 0 && isMoving != false)
        {
            if (isMoving)
            {
                isMoving = false;
                onStopMovement.Invoke();
            }
        }
    }
コード例 #2
0
    private void UpdateMovement()
    {
        float   x          = Input.GetAxis("Horizontal");
        float   z          = Input.GetAxis("Vertical");
        Vector3 moveVector = new Vector3(x, 0, z).normalized;

        if (moveVector != Vector3.zero)
        {
            var newPosition = transform.position + moveVector * speed * Time.deltaTime;
            OnPlayerMoved.Invoke(newPosition);
        }
    }