Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by intfloatbool · Mar 22, 2018 at 10:16 PM · unity 5collisioncolliderprogramming

How to specify in the GetComponent method in colliders?!

I broke my mind in 3 hours of thinking about it... I have UNIT he have several COLLIDERS (2) sphere (for get AGGRESSIVE) and Capsule Collider (not to be cross-cutting)

So I have a ROCKET that detonated when both Rigidbodies OnCollisionEnter() when rocket collision enter to unit collision make Explosion object with PArticle System and script with START method for check colliders from region (like in Unity3d lessons)

BUT problem: my unit have several colliders and one Script which can damage him so when I use foreach to find this creep I get SEVERAL unit-states component coz I have several colliders which Physycs.OverlapsSPhere returned!

         //Position Of Explosion
         Vector3 explode_pos = this.transform.position;
 
                
                  //for saving creep component
         ArrayList creeps = new ArrayList ();
 
         //get colliders from exposion radius
         Collider[] colliders = Physics.OverlapSphere(explode_pos, ExplodeRadius);
 
         int i = 0; //test
         //search for States component of creeps
 
         foreach(Collider col in colliders) {
 
                     //Which If statement using for get ONE StatesComponent from SEVERAL Colliders?
             if (col.GetComponent<CommonStatesBars> () == true && col.GetComponent<CapsuleCollider>() == true  ) {
                 
                 i++;
                 Debug.Log ("Collider#" + i + ", is: " + col.ToString()); 
             }
             
         }



Problem with that i try using DAMAGE to creep states component- i get it SEVERAL times (from both colliders)

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 intfloatbool · Mar 23, 2018 at 06:13 AM

Just do not use too many conditions :-)

My solution! :

 foreach (Collider col in colliders) {
     
                         
                 CommonStatesBars unit = col.GetComponent<CommonStatesBars> ();
     
                 if (unit != null) {
                     unit.MakeDamage (StaticWeapon.MissleDamage);
                 }
     
                 unit = null;
     
     
             }
 
 
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 Papnix · Mar 23, 2018 at 08:45 AM

Hello,

As you explain, I understand that you have both colliders set to "collider" (I mean by that not "trigger"). So I suggest you to make your "Agressive" collider a trigger (in the Collider component check "Is Trigger") and when you make your spherecast dont forget to Physics.raycastsHitTriggers == false.

You'll end up normally to only catch the colliders and not the triggers.

If you do that don't forget to change from OnCollisionEnter to OnTriggerEnter to handle your collisions with this new trigger !

I don't try this (I'm at work ; p) but I'm pretty sure it will work.

Have a nice day

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

253 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 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 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 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 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 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 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 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 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 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 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

Reloading a Scene Increases Gravity Acted on a Player 4 Answers

Remove Object from Game after Collision with Player (Unity 5.2.3f1) 1 Answer

HELP WITH COLLISIONS 0 Answers

How to trigger animation from object colliding with another? 0 Answers

Duplicate Remains After Destroying Object 1 Answer


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