Юнити помогите пожалуйста

версия юнити 2021.3.35f1 делаю шутер по видео вот видео https://yandex.ru/video/preview/4936954260784883410 хочу проверить персонажа ходьба и прыжок включаю весь скрипт на кнопку воспроизведения и персонаж летит бесконечно под карту когда удалил MovePlayer и GamingGravity персонаж полетел вверх вместе с картой исправьте мои ошибки пожалуйста

NullReferenceException: Object reference not set to an instance of an object
FPC.MovePlayer () (at Assets/Sсpripts/FPC.cs:101)
FPC.FixedUpdate () (at Assets/Sсpripts/FPC.cs:39)

    {
    public float speedMove;
    public float jumpPower;
    private float gravityForce;
    private Vector3 moveVector;
    private CharacterController ch_controller;

    public Joystick joy;
    public Transform cameraTransform;

    public float cameraSensitivity;
    
    private int rightFingerId;
    private float halfScreenWidth;

    private Vector2 lookInput;
    private float cameraPitch;

    public Transform player;
    void Start()
    {
        ch_controller = GetComponent<CharacterController>(); 
        rightFingerId = -1;
        halfScreenWidth = Screen.width / 2;
    }
    private void FixedUpdate()
    {
        MovePlayer();
        GamingGravity();
        if(rightFingerId != -1)
        {
           LookAround();
        }
    }  
       

    void Update()
    {
        GetTouchInput();
    }
     
    private void GetTouchInput()
    {

        for(int i = 0; i < Input.touchCount; i++)
        {
            Touch t = Input.GetTouch(i);

            switch(t.phase)
            {
               case TouchPhase.Began:
                   if(t.position.x > halfScreenWidth && rightFingerId == -1)
                   {
                       rightFingerId = t.fingerId;
                   }
                   break;
               case TouchPhase.Ended:
               case TouchPhase.Canceled:
                   if(t.fingerId == rightFingerId)
                   {
                       rightFingerId = -1;
                   }
                   break;
               case TouchPhase.Moved:
                   if(t.fingerId == rightFingerId)
                   {
                       lookInput = t.deltaPosition * cameraSensitivity * Time.deltaTime;
                   }
                   break;
               case TouchPhase.Stationary:
                   if(t.fingerId == rightFingerId)
                   {
                       lookInput = Vector2.zero;
                   }
                   break;
            }
        }    
    }    
    
    private void LookAround()
    {   
        cameraPitch = Mathf.Clamp(cameraPitch - lookInput.y, -90f, 90f);
        cameraTransform.localRotation = Quaternion.Euler(cameraPitch, 0, 0);
        transform.Rotate(transform.up, lookInput.x);
    }

    private void MovePlayer()
    {
        moveVector = Vector3.zero;
        moveVector.x = joy.Horizontal;
        moveVector.z = joy.Vertical;
        moveVector.y = gravityForce;

        moveVector = transform.right * moveVector.x + transform.forward * moveVector.z + transform.up * moveVector.y;

        ch_controller.Move(moveVector * speedMove * Time.deltaTime);
    }

    private void GamingGravity()
    {
        if(!ch_controller.isGrounded)
        {
              gravityForce -= 10f * Time.deltaTime;
        }
        else
            gravityForce = 0f;
    }


    public void OnClickJump()
    {
        if(ch_controller.isGrounded)
            gravityForce = jumpPower;
    }
}

Ответы (0 шт):