Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by PaxNemesis · Apr 19, 2011 at 04:21 PM · editorcollideroutline

Are there any way to show an objects collider outline through scripting?

I was wondering if there were any way to show another objects collider outline through scripting. Are there any way to set an outline active on an object that isn't currently marked? Done in an editor script?

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by zmar0519 · Apr 19, 2011 at 04:36 PM

Look up gizmos and look at the draw wireframe box function. That will work in the scene view. In the game view, I recommend using a line renderer with points at each corner, making a collider like box. A third option for the game view would be to purchase vectrocity.

Comment
Add comment · 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
1

Answer by tomatohorse · Feb 06, 2020 at 07:37 PM

Here's what I used that worked for me:

  public class ShowCollider : MonoBehaviour {
  
      [SerializeField] bool showCollider;
 
      void OnDrawGizmos() {
         if (showCollider){    
             Gizmos.color = Color.green;
             Gizmos.matrix = this.transform.localToWorldMatrix;
             Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
         }
     }
Comment
Add comment · 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
0

Answer by The_Pied_Shadow · Jan 06 at 02:39 PM

If you want this in gameplay

there is a solution if you're looking to visualize a collider in gameplay as I wanted to. I came across this thread, maybe someone else who is trying to do the same thing will too.

Working with 2D colliders, here is my code which uses a line renderer to draw the outline of any 2D collider.

Below "myCollider" is of type Collider2D, and "myLine" is of type LineRenderer with loop enabled.

 Mesh mesh = myCollider.CreateMesh(false, false);
 mesh.Optimize();
 
 Vector3[] positions = mesh.vertices;
 positions = positions.OrderBy(pos => Vector3.SignedAngle(pos.normalized, Vector3.up, Vector3.forward)).ToArray();
 
 myLine.positionCount = positions.Length;
 myLine.SetPositions(positions);

Note that you'll need to be using the namespace System.Linq for the OrderBy function. I've tested this successfully with the following 2D colliders: box, circle, capsule, and polygon. Hope it helps someone.

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

If statment to check if player is within collider 1 Answer

"if(hit.collider.gameObject.name == gameObject.name)" only compares as true on the gameObject that first recieved the script 1 Answer

physics2d.raycastall help please 1 Answer

Making a Ball Respawn after collision with Goal? 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