Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by saver1991 · May 02, 2014 at 05:54 PM · debugdrawlinedebug.drawline

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?

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ThePunisher · May 02, 2014 at 05:57 PM 0
Share

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?

avatar image roojerry · May 02, 2014 at 05:59 PM 0
Share

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

avatar image saver1991 · May 02, 2014 at 06:32 PM 0
Share

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?

avatar image robertbu · May 02, 2014 at 06:47 PM 0
Share

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?

avatar image saver1991 · May 03, 2014 at 11:17 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · May 02, 2014 at 06:43 PM 5
Share

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.

avatar image ThePunisher · May 02, 2014 at 08:21 PM 0
Share

Oh that's cool. I didn't know you could make that visible in the game view.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges