I’m trying to make an FNaF fangame that has a 360 View of the Office, and where if you look at an interactable you can click and it will do its function.
the problem is that for some unknown reason (I SPECULATE that it is because the cursor randomly disconnects from the monitor containing the game view) it keeps sending me an Nullreferenceexception at random moments.
it SAYS That there is nothing used for calls to other functions. but the problem is, there is NOTHING to set a REFERENCE TO.
I tried asking about this on discord, but while I understand that they might be bussy ATM, I was at my wit’s end and so decided to ask for help here
the code for the three scripts
the script that calculates what is being looked at
The Interaction Physics Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player_interactions_script : MonoBehaviour
{
public player_look_script donations;
public Camera player;
private bool interactionToggle;
private Ray line;
[Range(0.5f, 2.5f)]
public float distance = 0.5f;
public LayerMask devicesLayer;
private device_manager donation_reciever;
private void Awake()
{
player = donations.player;
}
// Update is called once per frame
private void FixedUpdate()
{
sightphysics();
}
void sightphysics()
{
line = new Ray(player.transform.position, player.transform.forward);
RaycastHit interactionHit;
interactionToggle = Physics.Raycast(line, out interactionHit, distance, devicesLayer);
if (interactionToggle)
{
if(interactionHit.collider.tag == "Light Button")
{
donation_reciever.light_toggle();
}
else if(interactionHit.collider.tag == "Door Button")
{
donation_reciever.door_toggle();
}
}
}
}
the code meant for each individual ‘device’
The Devices Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class device_manager : MonoBehaviour
{
public GameObject doorButton;
public GameObject lightButton;
private bool lightEnabled;
private bool doorEnabled;
private void Awake()
{
lightEnabled = false;
doorEnabled = false;
}
// Update is called once per frame
public void light_toggle()
{
if (Input.GetMouseButton(0))
{
Debug.Log("Sucess");
}
}
public void door_toggle()
{
}
}
I would REALLY love an Idea asto whats causing the NullReferenceException