• 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 brenolimaa96 · May 02, 2016 at 11:47 AM · 2dcollisiongameobjecttransformscene

1 collider 2 fuctions, how?

How to set a function to the upside part of the collider ?

i have an object with a collider, I want to the top part do some function, and the down part do other. how should i do that?

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 Raresh · May 02, 2016 at 11:48 AM 0
Share

Please be more specific on these "functions"

avatar image brenolimaa96 · May 02, 2016 at 11:50 AM 0
Share

about the function, is about killing when jump on enemies head, I know how to do that.

i just dont know how to set to happens only in the top part of the collider. actually, in my game, i'm killing monster and losing life at the same time. i dont want in that way.

avatar image Cherno · May 02, 2016 at 11:52 AM 0
Share

It'd be easier to use two seperate GameObjects with each having it's own collider, possibly in a parent-child hierarchy. If you really want it on one, then you'd have to decide which function to call by comparing the colliders' bounds,center.y, for example.

avatar image brenolimaa96 Cherno · May 02, 2016 at 11:54 AM 0
Share

Great cherno, i will study about thouse bounds and center. I've already tried with 2 colliders and wouldn't work, since the child get properties of the collider from the parent. I'll try something here and if it works, i'll return.

avatar image brenolimaa96 · May 02, 2016 at 12:09 PM 0
Share

Hey guys, that's what i want to do, just dont know how. take a look.

 void OnCollisionEnter2D(Collision2D colisor)
     {
         if (colisor.gameObject.name.Equals("Player") // && downpart) 
         {
             damage.Attack();
         }
 
         if (colisor.gameObject.name.Equals("Player") // && topPart)
         {
             RbPlayer.AddForce (new Vector2 (0, 150));
             die= true;
             
         }
         
     }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Amanna · May 16, 2016 at 02:59 PM

you can use two gameObjects with separate boxCollider , and add two different scripts on that like ..

void OnCollisionEnter2D(Collision2D colisor) ///// in first script { if (colisor.gameObject.name.Equals("Player") // && downpart) { damage.Attack(); } }

void OnCollisionEnter2D(Collision2D colisor) /////// in second script { if (colisor.gameObject.name.Equals("Player") // && downpart) { damage.Attack(); } }

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

82 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

Related Questions

[2D] Unsure why a gameObject is randomly falling through the floor instead of being transformed to the player 0 Answers

Is there a solution to when colliders bypass? 2 Answers

How to move a Game Object from a script not attached to it. 1 Answer

collision2D not working - help? 2 Answers

Trouble Descaling 2D 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