Quantcast
Channel: Latest Questions by LlamaNervous
Viewing all articles
Browse latest Browse all 48

NullReferenceException in game build

$
0
0
I just built my first person horror game and upon a quick playthrough, when I reach the second level, the camera cannot move up or down but everything else can happen. When I went back to Unity to see what the problem was, it didn't happen, it only happens in the built version of the game. When I bring up the developer console in the build it comes up with NullReferenceException error? I think it's an error. After searching the unity Answers for a while I tested that the camera in my controller is tagged as main camera and as far as I can tell, there are no other cameras in the scene. using UnityEngine; using System.Collections; [RequireComponent (typeof(CharacterController))] public class FirstPersonController : MonoBehaviour { public float forwardmovementSpeed = 7.0f; public float sidemovementSpeed = 5.0f; public float jumpSpeed = 0.1f; public float mouseXSensitivity; public float mouseYSensitivity; float verticalRotation = 0; public float upDownRange = 60.0f; float verticalVelocity = 0; CharacterController characterController; public float Stamina = 10; public bool Run; void Awake () { DontDestroyOnLoad(gameObject); } void Start () { mouseXSensitivity = PlayerPrefs.GetFloat("Sensitivity"); mouseYSensitivity = PlayerPrefs.GetFloat("Sensitivity"); Screen.lockCursor = true; characterController = GetComponent(); Camera.main.fieldOfView = PlayerPrefs.GetInt("FOV"); } void Update () { //ROTATION float rotLeftRight = Input.GetAxis("Mouse X") * mouseXSensitivity; transform.Rotate (0, rotLeftRight, 0); verticalRotation -= Input.GetAxis("Mouse Y") * mouseYSensitivity; verticalRotation = Mathf.Clamp(verticalRotation, -upDownRange, upDownRange); Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0); //MOVEMENT float forwardSpeed = Input.GetAxis("Vertical") * forwardmovementSpeed; float sideSpeed = Input.GetAxis("Horizontal") * sidemovementSpeed; verticalVelocity += Physics.gravity.y * Time.deltaTime; if(characterController.isGrounded && Input.GetButtonDown("Jump")) { verticalVelocity = jumpSpeed; } Vector3 speed = new Vector3(sideSpeed, verticalVelocity, forwardSpeed); speed = transform.rotation * speed; characterController.Move(speed * Time.deltaTime); if(Input.GetKeyDown(KeyCode.LeftShift)) { if(Stamina > 0) { Run = true; forwardmovementSpeed = 7f; sidemovementSpeed = 5f; } } if(Stamina <= 0) { forwardmovementSpeed = 3f; sidemovementSpeed = 3f; Run = false; } if(Input.GetKeyUp(KeyCode.LeftShift)) { forwardmovementSpeed = 3f; sidemovementSpeed = 3f; Run = false; } if(Run == true) { Stamina -= Time.deltaTime; } else { if(Stamina < 10) { Stamina += Time.deltaTime; } } if(Input.GetKeyDown(KeyCode.F1)) { Application.LoadLevel(3); } } } Any help would be appreciated.

Viewing all articles
Browse latest Browse all 48

Trending Articles



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