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 error while using camera.main.fieldOfView

$
0
0
using System.Collections; using System.Collections.Generic; using UnityEngine; public class cameraControl : MonoBehaviour { public GameObject Player ; public GameObject cameraConstraint; public GameObject CameralookAt; private controller RR; private float speed = 0; public float defaltFOV, dsiredFOV = 0; [Range(0,2)] public float smothTime = 0; private void Awake () { Player = GameObject.FindGameObjectWithTag("Player"); cameraConstraint = Player.transform.Find("camera constraint").gameObject; CameralookAt = Player.transform.Find("camera LookAt").gameObject; RR = Player.GetComponent(); } private void update (){ } private void FixedUpdate() { follow(); boostFOV(); } private void follow(){ if(speed <= 23) speed = Mathf.Lerp(speed , RR.KPH / 2 ,Time.deltaTime); else speed = 23; gameObject.transform.position = Vector3.Lerp(transform.position,cameraConstraint.transform.position,Time.deltaTime * speed); gameObject.transform.LookAt(Player.gameObject.transform.position); defaltFOV = Camera.main.fieldOfView; } private void boostFOV (){ if(Input.GetKey(KeyCode.LeftShift)) Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, dsiredFOV, Time.deltaTime * smothTime); else Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, defaltFOV, Time.deltaTime * smothTime); } } Error= NullReferenceException: Object reference not set to an instance of an object cameraControl.follow () (at Assets/programming/cameraControl.cs:42) cameraControl.FixedUpdate () (at Assets/programming/cameraControl.cs:30)

Viewing all articles
Browse latest Browse all 2891

Trending Articles



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