Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question