• 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 11:12 AM · colliderhitifthis

if hit something

hi,

does anybody of you know how I can do that if a gameobject (with a collider) hits an object it does something like this: 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 Arachnos · Jun 19, 2011 at 11:36 AM

Using Javascript you would do something like this:

function OnTriggerEnter(otherObject: Collider){

if(otherObject.gameObject.tag == "Robot"){

blabla();

}

You would also have to create a tag and name it Robot, then select that tag on the object you want to collide. Also you might have to set one of the 2 objects that are colliding to be the trigger.

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 Unamine · Jun 19, 2011 at 11:45 AM

This is easy, for more information visit this link: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html

Any questions, ask ;D Hope this help

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 realm_1 · Jun 19, 2011 at 11:54 AM

Collider enter:

function OnColliderEnter (hit : Collision) { Destroy(hit.gameObject); }

Trigger enter:

function OnTriggerEnter (hit : Collider) { Destroy(hit.gameObject); }

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 bubblegumsoldier · Jun 19, 2011 at 12:19 PM 0
Share

thx for all these fast information...

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

ERROR: why is showing red OnControllerColliderHit? 2 Answers

BCE0023: No appropriate version of 'UnityEngine.Random.Range' for the argument list '(System.Object)' was found. 0 Answers

How to hit two object with one raycast? 2 Answers

Raycasting and receiving hit.colliders with two cameras 0 Answers

Collision Not Responding 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges