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
0
Question by largow · Apr 14, 2014 at 03:17 AM · 2dcolliderspolygonpolygoncollider2d

Getting multiple Polygon Collider 2D on script

Hello guys, I have a character in my game and I have different PolygonCollider2D attached to them, in order to enable/disable them depending on which sprite animation is playing at the moment. That is because the idle animation is different than the running or jumping one, so as I can't edit the vertices of the PollygonCollider, I just attached 3 of them with all of them having different shapes of course.

The thing is i don't know how to identify these components in order to get them by script and enabling or desabling them. I can make:

 PolygonCollider2D collider1 =  gameObject.GetComponent<PolygonCollider2D> ();

But I don't know which one would be cause there's nothing there to identify them.

Thanks in advance.

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

2 Replies

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

Answer by largow · Apr 14, 2014 at 12:47 PM

Your answer was useful. Thanks!

I also found another way, by doing this thing:

 public PolygonCollider2D[] lstPolCols;
 
     void Start(){
       lstPolCols = gameObject.GetComponents<PolygonCollider2D> ();  //use GetComponents 
       //And now i enable or disable them just when i want to: Example:
       if(character.IsRunning())
           lst.PolsCols[1].enabled = true; 
           //cause the 'running' polygon collider is the second one i attached,
           // so it will be at the second position [1].   
 
       }
 }
Comment
Add comment · Show 1 · 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 rebb_ · Aug 20, 2014 at 06:48 AM 0
Share

I am working on game where i have three different sprites for hero guy. Up,middle and down.

I did multiple colliders as here suggested. I can assign colliders easily and change them to correspond sprite i am showing.

However if i drag sprites to different PolygonCollider2D's it automatically updates rest of colliders to same shape. So if i drag down position sprite to any PolygonCollider2D's also the rest of the colliders have same shape.

Am i missing something here?

avatar image
0

Answer by Patel-Sagar · Apr 14, 2014 at 05:47 AM

You can get reference of each of them in start. you can define it public as below.

public PolygonCollider2D p1, p2, p3;

then you can add reference to it in inspector itself by drag and drop.

if you are creating these colliders in start by addComponent, then you can give reference there also as below.and then use this variable to access in whole script.

p1 = gameObject.AddComponent(); print(p1.points.Length);

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

23 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

Related Questions

2d Collision 0 Answers

what collider to use for 2d movement? 1 Answer

Colliders at wrong position after building the game? 1 Answer

Polygon Collider 2D doesn't have the "edit collider" button avaliable. 0 Answers

Two colliders on GameObject with only one acting as trigger 2 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