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

NullReferenceException: Object reference not set to an instance of an object. (Cameras switching)

$
0
0
Hi! I want to make script that will change camera on "E" button when player is standing in trigger, but when I change Camera to Car camera (CCamera) then this error is displaying. Please help, thank you! using System.Collections; using System.Collections.Generic; using UnityEngine; public class Auto : MonoBehaviour { void Start() { var FPSCamera = GameObject.FindGameObjectWithTag("MainCamera"); var CCamera = GameObject.FindGameObjectWithTag("CCamera"); CCamera.SetActive(false); FPSCamera.SetActive(true); } void OnTriggerStay(Collider other) { var FPSCamera = GameObject.FindGameObjectWithTag("MainCamera"); var CCamera = GameObject.FindGameObjectWithTag("CCamera"); if (Input.GetKeyDown(KeyCode.E)) { CCamera.SetActive(true); FPSCamera.SetActive(false); } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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