Share via

NullReferenceException: Object reference not set to an instance of an object

Simranpreet Kaur Deol 1 Reputation point
2022-11-30T01:42:20.587+00:00

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

public class PlayerController : MonoBehaviour
{
private Rigidbody playerRB;
public GameObject focalPoint;
public float speed = 30;

// Start is called before the first frame update  
void Start()  
{  
    playerRB = GetComponent<Rigidbody>();  
    focalPoint = GameObject.Find("Focal Point");  
}  

// Update is called once per frame  
void Update()  
{  
    float forwardInput = Input.GetAxis("Vertical");  
    playerRB.AddForce(focalPoint.transform.forward * forwardInput * speed);  
}  

}

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.