- Home /
Debug.DrawLine doesn't work
Hi Everyone! I'm trying to create a 2d platform game and have a problem with the Debug.DrawLine function to create a raycast for spotting the player by the guard. I'm following this tutorial: http://www.youtube.com/watch?v=cJj7-Sy03HQ and he don't have any problem because the line is drawed correctly. This is the code used:
using UnityEngine;
using System.Collections;
public class GuardLogic : MonoBehaviour {
public Transform startPoint, endPoint;
public bool spotted = false;
void update() {
Raycasting ();
Behaviours ();
}
void Raycasting() {
Debug.DrawLine (startPoint, endPoint, Color.red);
spotted = Physics2D.Linecast(startPoint.position, endPoint.position, 1 << LayerMask.NameToLayer("Player"));
}
void Behaviours() {
}
}
Anyone know how is it possible? Maybe he use an old version and the API are changed?
You didn't say what the actual problem is.... Are you not seeing the line? Is it not going the direction you thought it should?
Did you make sure to set those transforms in the Inspector? i.e. drag and drop your start and end point to those values on the script
The problem is that I didn't see the line and also monodevelop give me error when I insert this:
spotted = Physics2D.Linecast(startPoint.position, endPoint.position, 1 << Layer$$anonymous$$ask.NameToLayer("Player"));
What could be the problem?
For the Debug.DrawLine(), make sure the 'Gizmos' button in the upper right corner of the Game windows is pressed.
As for the line of code, what error did you get?
Sorry, I don't get any errors. I can start play the game without error using the code but the line is not visibile in the game view and in the scene view...I don't really understand what the problem can be
Answer by M_Dizzle · May 02, 2014 at 06:41 PM
Debug.Drawline is only visible on the Scene view, not Game mode. Your could use LineRenderer if you need to be able to see it in the game.
Only partly right. If you click on the 'Gizmos' button in the upper right of the game window, then Debug.DrawLine() will be visible in the Game view.
Oh that's cool. I didn't know you could make that visible in the game view.
Your answer
Follow this Question
Related Questions
Raycast and Debug Line Position 1 Answer
Debug.DrawLine Stops Functioning In Game View (Editor) When SteamVR plugin Is Imported 0 Answers
OnDrawGizmos Debug.DrawLine position is pinching when rotated. 0 Answers
Selecting custom game objects in Scene view window. 1 Answer
Converting Debug.drawlines to in-game lines? [screenshot inside] 3 Answers