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 bdr · Feb 27, 2011 at 04:28 AM · collisionobjectvariablecolliderotating

how to make a script when u collide with an object it disappears

how do u make a script when u collide with a rotating object, it disappears and subtracts 1 from a variable?

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
3
Best Answer

Answer by Joshua · Feb 27, 2011 at 12:03 PM

I don't know why people keep posting answers here where they use triggers wrong. Triggers are intended to for instance make an invisible forcefield that when you walk through it the door in front of you slides open. You 'can' use them for collision, but it's easier to just use:

var score : int = 10;

 function OnCollisionEnter (col : Collision) { 
 if(col.gameObject.Tag == "Player"){ 
 score -=1; 
 Destroy(gameObject); 
 }
 }

Now all you have to do is attach this to the rotating object and make sure your playercharacter has the tag Player. :)

Comment
Add comment · Show 4 · 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 by0log1c · Mar 05, 2011 at 04:51 AM 0
Share

Just wanted to point out the accepted answer should be: OnCollisionEnter and not OnCollisSionEnter . At least I guess so...

avatar image Joshua · Mar 05, 2011 at 03:09 PM 0
Share

Ouch. Edited. :)

avatar image shane-icelander · Mar 19, 2014 at 12:35 AM 0
Share

I believe that it is because of the unnecessary calculations involved if you are not actually using anything from the Collision class. If you just want to know if one gameObject entered another gameObject, then using a trigger is fine. From Unity: In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached. http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html

avatar image 1o482013581451 · Apr 25, 2015 at 06:42 PM 0
Share

This does not work. Jees, how old is it!

avatar image
1

Answer by AVividLight · Feb 27, 2011 at 05:15 AM

This is what I would use...

var score : int = 10; var objectTag : String = "Put The GameObjects Tag Here";

function OnCollissionEnter (collidedObject : Collision) { if(collidedObject.gameObject.tag == objectTag){ score -=1; Destroy(gameObject); } }

-Hope I Helped!


Thanks Joshua for the original code...

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 Joshua · Feb 28, 2011 at 08:21 PM 0
Share

Yeah, that's even neater. I'm fairly new to scripting myself and trying to make my style more neat, so thanks. :)

avatar image AVividLight · Feb 28, 2011 at 08:53 PM 0
Share

Yeah, I'm glad I could help, and I wish you luck in your hunt for gold (Learning Scripting) :)

avatar image AVividLight · Feb 28, 2011 at 08:53 PM 0
Share

Let me know if you have any other questions!

avatar image
0

Answer by Noah-1 · Feb 27, 2011 at 04:56 AM

It would be something like this:

var MyVar = 10;

function OnTriggerEnter (other : Collider) {

if (other.CompareTag ("HERE YOUR TAG NAME")) {

   Destroy (gameObject);

  MyVar--;


} }

I hope it helps, good Luck.

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

1 Person is following this question.

avatar image

Related Questions

Collision between objects 2 Answers

how to make a script when an object collides with an object it makes another object rise 2 Answers

How to get Raycast to detect collision with Object? 3 Answers

collision with objects, physics 1 Answer

Objects Touching? 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