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 /
avatar image
0
Question by bubblegumsoldier · Jun 19, 2011 at 12:00 PM · colliderhitrobot

hit something with collider

how can I do it that if something hits something it does something?

for example:

if(Robot.hit(this)){ blabla(); }

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

Answer by LegionIsTaken · Jun 19, 2011 at 12:34 PM

 function OnCollisionEnter(hit : Collision)
 {
 if(hit.gameObject)
     {
      blabla();
     }
 }
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 Merglasch · Jun 19, 2011 at 12:42 PM

Hey there,

Take a look into the Unity Script Reference. There are 6 functions for collision detection.

OnTriggerEnter

OnTriggerStay

OnTriggerExit

OnCollisionEnter

OnCollisionStay

OnCollisionExit

 They're used like this:
 void OnTriggerEnter(Collider other){ //the collider other collides with assigned object  
 do this
 } 

Be aware you need to attach colliders,triggers and rigidbodys for your collisions to occur

Here's a link to the reference: http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=collision

also you can check the manual about Rigidbodies. There's some useful information in there

regards

Comment
Add comment · Show 3 · 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 bubblegumsoldier · Jun 19, 2011 at 02:12 PM 0
Share

and how can I do it that it does something when it hits anything?

avatar image Merglasch · Jun 19, 2011 at 02:32 PM 0
Share

since you can define the collider other yourself that's pretty much everything isn't it? leaving the collider empty might also work (depends)

Also at the OnCollision events the Collision information is proceeded ins$$anonymous$$d of the collider info. (void OnCollisionEnter(collisionInfo : Collision).

avatar image bubblegumsoldier · Jun 20, 2011 at 10:42 AM 0
Share

well I want that it does a sound when it hits something could anybody do a code for this because i tried diefferent things but nothing worked

avatar image
0

Answer by bubblegumsoldier · Jun 19, 2011 at 02:23 PM

and how can I do it that it does something when it hits anything?

(I wrote a comment but nobody answered so sorry for this "answer".)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Raycast Destroy(hit.collider.gameObject); (Still need help) 1 Answer

Accesing Player colliderhit with other gameobject? 2 Answers

The Child Is Not Hovered When Passing The Parent's Collider 0 Answers

Raycast2D doesn't detect objects 1 Answer

ERROR: why is showing red OnControllerColliderHit? 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