Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Raycast not stopping on hit?

Discussion in 'Scripting' started by Endzone, Nov 6, 2015.

  1. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119
    Hello , im Creating a Voxel game and if i place two blocks beside one another and destroy them The raycast seems to go through the first collider and hit the one behind it also? im not too sure what im doing wrong but hears my code Hopefully someone can give me some tips or help me fix it! - thanks :)


    Code (CSharp):
    1. if (Input.GetMouseButtonDown(0) && Inventopen != true) {
    2.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.             RaycastHit hit;
    4.             if (TriggerCollider.Raycast(ray, out hit, 4.0F)){
    5.                 Debug.Log ("HitBlock");
    6.             }
    7.            
    8.         }
     
  2. Okto247

    Okto247

    Joined:
    Jun 26, 2015
    Posts:
    7
  3. Endzone

    Endzone

    Joined:
    Dec 18, 2014
    Posts:
    119