Hello people, I would like to thank you for the help.
I have a problem with Raycast, the code works well in another scene, but in which I need it I get an error.
NullReferenceException: Object reference not set to an instance of an object
RayCast.Update ()
I have deactivated everything, to see that they do not affect the scripts, in the RayCast script execution.
I want to know what happens, I do not understand why it does not work.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class RayCast : MonoBehaviour {
public LayerMask ClickLayer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
private void Update()
{
if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
{
RaycastHit hitInfo;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hitInfo, 100.0f, ClickLayer))
{
Debug.Log(hitInfo.collider.name);
}
}
}
}
regards