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.
NullReferenceException: Object reference not set to an instance of an object
Simranpreet Kaur Deol
1
Reputation point
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#
Sign in to answer