S
S
SankiG2020-12-19 18:48:39
Unity
SankiG, 2020-12-19 18:48:39

How to fix NullReferenceExpencion error?

The NullReferenceExpencion error comes out in the line that I numbered 15, how to fix it?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent (typeof(Rigidbody2D))]
public class PlayerCntrl : MonoBehaviour {

  public float runSpeed = 3f;
  public float jumpForce = 5f;   
  private Rigidbody2D rb;

  void Start(){
    rb = GetComponent<Rigidbody2D> ();
  }

  public void Jump(){
  15.	rb.AddForce(transform.up*jumpForce, ForceMode2D.Impulse); 
  }
  public void Move(float ax){
    Vector3 direction = transform.right * ax;
    transform.position = Vector3.Lerp (transform.position, transform.position + direction, runSpeed * Time.deltaTime);
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-12-19
@freeExec

Don't jump before the start.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question