i need help trying to find out how i can set mt raycast to false after i have moved my raycast of a object. i have set it up with a bool, but it doesn’t uncheck when i move of the object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float Maxdistance = 10;
public LayerMask layermask;
public bool ObjectHit = false;
void Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Maxdistance, layermask))
{
if (hit.collider != null)
{
ObjectHit = true;
print(hit.transform.name);
}
}
if (Physics.Raycast(ray, out hit, Maxdistance, layermask))
{
if (hit.collider == null)
{
ObjectHit = false;
}
}
}