Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Need help fixing error (NullReferenceException: Object reference not set to an instance of an object)

$
0
0
So here's my code: using UnityEngine; using System.Collections; using UnityStandardAssets.Vehicles.Car; using UnityStandardAssets.Characters.FirstPerson; public class ControllerManager : MonoBehaviour { private CarUserController CarController; private RigidbodyFirstPersonController Player; private CarAudio CarSound; public Camera PlayerCamera; public Camera CarCamera; // Use this for initialization void Start () { CarController.enabled = false; Player.enabled = true; CarSound.enabled = false; CarCamera.enabled = false; PlayerCamera.enabled = true; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E)) { SwitchCamera(); } } void SwitchCamera() { CarController.enabled = !CarController.enabled; CarCamera.enabled = !CarCamera.enabled; CarSound.enabled = !CarSound; Player.enabled = !Player.enabled; PlayerCamera.enabled = !PlayerCamera.enabled; } } I get the error on line 15: CarController.enabled = false; I made this script for switching the player and car controllers. It's weird because the car controller is getting the error, but the player controller isn't (Player is the player controller btw). Anyway, anyone know where I went wrong? EDIT: I just realized that the same thing is happening with all of Unity's car scrips.... almost same exact thing. Here's the one for cross-platforming controlls: using System; using UnityEngine; using UnityStandardAssets.CrossPlatformInput; namespace UnityStandardAssets.Vehicles.Car { [RequireComponent(typeof (CarUserController))] public class CarUserControl : MonoBehaviour { private CarUserController m_Car; // the car controller we want to use private void Awake() { // get the car controller m_Car = GetComponent(); } private void FixedUpdate() { // pass the input to the car! float h = CrossPlatformInputManager.GetAxis("Horizontal"); float v = CrossPlatformInputManager.GetAxis("Vertical"); #if !MOBILE_INPUT float handbrake = CrossPlatformInputManager.GetAxis("Jump"); m_Car.Move(h, v, v, handbrake); #else m_Car.Move(h, v, v, 0f); #endif } } } The error is on line 27: m_Car.Move(h, v, v, handbrake);

Viewing all articles
Browse latest Browse all 2891

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>