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 djary · Dec 08, 2013 at 07:55 AM · box collidercolider

How to enable/disable two box colliders in one object ?

hi all

How to enable/disable two box colliders in one object ?

i have 2 box colliders :

1- box collider has isTrigger

and other one

2- box collider

i have code but only enable/disable "boxcollider isTrigger" and no affect on secend boxcollider !

my code is :

this.collider.enabled = true/false;

how can i enable/disable Both box colliders ?

Comment
Add comment · Show 6
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 djary · Dec 08, 2013 at 08:13 AM 0
Share

down't work

avatar image tomekkie2 · Dec 08, 2013 at 08:24 AM 0
Share

I have just tested that in empty test scene and it does work for me. But also to get your code to work, I have to put

 gameObject.GetComponents<BoxCollider>().enabled
 = false;

ins$$anonymous$$d of your this.collider.enabled = false;

avatar image djary · Dec 08, 2013 at 08:32 AM 0
Share

can put javascript code ?

avatar image tomekkie2 · Dec 08, 2013 at 09:05 AM 0
Share

not much different in JS

 var myColliders: BoxCollider[] = gameObject.GetComponents.<BoxCollider>();
 for (var bc : BoxCollider in myColliders) bc.enabled=false;
avatar image djary · Dec 08, 2013 at 09:30 AM 0
Share

tanQ very much this is work !!!!!!!!!

tanx man

Show more comments

2 Replies

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

Answer by tomekkie2 · Dec 08, 2013 at 08:06 AM

Looks like this.collider references the first of your colliders. You should use:

 BoxCollider[] myColliders = gameObject.GetComponents<BoxCollider>();

to get an array of colliders attached and loop through the array.

 foreach(BoxCollider bc in myColliders) bc.enabled = false;
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 CristianGman · Oct 10, 2017 at 07:13 AM 0
Share

Is it possible to make an array of different Collider types and turn each one off in an array as well?

avatar image
1

Answer by jchart7 · Aug 24, 2014 at 06:12 PM

if you need to turn off / on Sprite collider inside a function use

gameObject.collider2D.enabled = false;

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

20 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

Related Questions

Whats the best colider to use for my race track? 0 Answers

Using a colider to detect presence of a trigger (C#) 1 Answer

Problem with collisions of my grab object 1 Answer

Box Collider Panel Controls Bounding Box Visibility? 2 Answers

2d collision with "unwalkable" objects 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