# Help... (789923)

**URL:** https://discussions.unity.com/t/help-789923/789923
**Category:** Physics
**Tags:** Scripting
**Created:** [May 9, 2020, 12:10pm UTC](https://discussions.unity.com/t/help-789923/789923 "2020-05-09T12:10:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ShaunChad99](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@ShaunChad99](https://discussions.unity.com/u/ShaunChad99)
#### Post date: [May 9, 2020, 12:10pm UTC](https://discussions.unity.com/t/help-789923/789923/1 "2020-05-09T12:10:22Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![Yoreki](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/yoreki/32/155895_2.png) [@Yoreki](https://discussions.unity.com/u/Yoreki)
#### Post date: [May 9, 2020, 12:25pm UTC](https://discussions.unity.com/t/help-789923/789923/2 "2020-05-09T12:25:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ShaunChad99](https://avatars.discourse-cdn.com/v4/letter/s/67e7ee/32.png) [@ShaunChad99](https://discussions.unity.com/u/ShaunChad99)
#### Post date: [May 9, 2020, 12:35pm UTC](https://discussions.unity.com/t/help-789923/789923/3 "2020-05-09T12:35:20Z")

</div>

t

> [@Yoreki](#):
>
> 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.

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