Help...

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;
            }
        }
     }

You have two raycasts. If no object is hit, the second check is skipped, thus if hit.collider == null, the check for that is not even executed and ObjectHit = false is never set… Just set ObjectHit = hit.collider != null behind the first raycast and remove the second.

t

thanks you just needed that little bit of help on my first raycast script