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

Test Script from Unity Docs not working

Discussion in 'Getting Started' started by MathewAlden, Jun 20, 2016.

  1. MathewAlden

    MathewAlden

    Joined:
    Nov 10, 2013
    Posts:
    12
    Hello, hopefully this is the right place to put this.

    I was learning how to use raycasting to detect an object's surface normals. I made a simple scene with a capsule, a sphere, a light, and the camera. Into the camera I added the script found here, setting the capsule to be the
    gunObj. I then ran my project, but when I clicked the sphere nothing happened. Using Debug.LogError, I figured out that the if(Input.GetMouseButton(0)) was being entered, but the debugging lines aren't being drawn for some reason. What am I doing wrong?

    Thanks!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    What about the next if? The "if (Physics.Raycast(ray, out hit))" block? Put another Debug.Log there to see.

    If you're getting there, but not seeing the lines, then you're either looking in the wrong place (these debug lines appear only in the Scene tab, not in the Game tab), or your scene view isn't configured correctly to see them (I believe you can turn these on/off in the scene tab settings).

    If you're not getting in there, then the raycast isn't hitting anything — perhaps your sphere doesn't have a collider, or it's set to be a trigger.
     
    MathewAlden likes this.
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,999
    Also do you have gizmos enabled in game window? (on the top right corner, click "Gizmos" to enable)
     
    MathewAlden likes this.
  4. MathewAlden

    MathewAlden

    Joined:
    Nov 10, 2013
    Posts:
    12
    Awesome that's what I needed. I didn't have gizmos on. Thanks for the help guys.