Hello, im completing the Complete C# Unity Game Developer 2D course, im on the second game and for some reason when i try to add the boost it says “NullReferenceException: Object reference not set to an instance of an object PlayerController.RespontToBoost”
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float torqueamount = 1f;
[SerializeField] float speedamount = 30f;
[SerializeField] float basespeed = 20f;
Rigidbody2D rb2d;
SurfaceEffector2D surfaceEffector2D;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
void Update()
{
RotatePlayer();
RespondToBoost();
}
void RespondToBoost()
{
if (Input.GetKey(KeyCode.UpArrow))
{
surfaceEffector2D.speed = speedamount;
}else
{
surfaceEffector2D.speed = basespeed;
}
}
void RotatePlayer()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
rb2d.AddTorque(torqueamount);
}
else if (Input.GetKey(KeyCode.RightArrow))
{
rb2d.AddTorque(-torqueamount);
}
}
}