Search Unity

Question Why my Debug.DrawLine doesn't show up?

Discussion in 'Navigation' started by av0cadowhere, Jun 9, 2022.

  1. av0cadowhere

    av0cadowhere

    Joined:
    May 27, 2022
    Posts:
    2
    For my project I am using Area Target and baked NavMesh as a path. I have been terribly frustrated with the Debug.DrawLine. I just using scripting API by Unity but I don't know why it doesn't show up. I try use another project which is on cube object as a NavMesh path suddenly it show up.

    So this is the script that I used which is from Unity.

    Code (CSharp):
    1. // ShowGoldenPath
    2. using UnityEngine;
    3. using UnityEngine.AI;
    4.  
    5. public class ShowGoldenPath : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     private NavMeshPath path;
    9.     private float elapsed = 0.0f;
    10.     void Start()
    11.     {
    12.         path = new NavMeshPath();
    13.         elapsed = 0.0f;
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         // Update the way to the goal every second.
    19.         elapsed += Time.deltaTime;
    20.         if (elapsed > 1.0f)
    21.         {
    22.             elapsed -= 1.0f;
    23.             NavMesh.CalculatePath(transform.position, target.position, NavMesh.AllAreas, path);
    24.         }
    25.         for (int i = 0; i < path.corners.Length - 1; i++)
    26.             Debug.DrawLine(path.corners[i], path.corners[i + 1], Color.red);
    27.     }
    28. }

    upload_2022-6-9_11-56-23.png

    Is there anyone knows why it doesn't show up? Supposedly it shows from bottom of the camera to another gameObject.

    Or it has something missing that I don't know in order to setup the Area Target and AI navigation?
     
    Last edited: Jun 9, 2022