I tried so many things but i dont get it.
Probably gameObject souldnt be null but how to fix it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interactor : MonoBehaviour
{
public LayerMask interactableLayermask = 16;
//Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 2, interactableLayermask))
{
if(Input.GetKeyDown(KeyCode.E))
{
GetComponent<PageScript>().pages++;
Destroy(hit.collider.gameObject);
}
}
}
}
Error:
NullReferenceException: Object reference not set to an instance of an object
Interactor.Update () (at Assets/My Game/C# Scipts/Interactor.cs:23)