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 sam32x · Oct 19, 2011 at 11:53 AM · collisiononcollisionentersomething

nothing happens on collision ever

script:

 var health = 60;
 var something : GameObject;

 function OnCollisionEnter(thing : Collision) {
     if (thing.collider.tag == "Bullet") {
     health -= 1;
     }
     else
     if (thing.collider.tag == "FlameBall") {
     health -= 3;
     }
     else
     if (thing.collider.tag == "Bomb") {
     health -= 6;
     }
     }
     
     function Update () {
     if (health <= 0)
     Destroy (something);
     Debug.Log(health);
     }

nothing happens on collision, health always stays at 60 also i have never been able to do a collision properly in the 1 1/2 months i have had unity. the script is attached, something is assigned, the projectiles have sphere colliders and the target has a rigidbody. the console says there are no errors.

Comment
Add comment · Show 2
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 Uniquesone · Oct 19, 2011 at 12:09 PM 1
Share

Ehh same as here?

http://answers.unity3d.com/questions/177382/oncollisionenter-nothing-is-happening.html

avatar image sam32x · Oct 19, 2011 at 12:23 PM 0
Share

yeah but i didnt get an answer that worked

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Oct 19, 2011 at 12:39 PM

This script works fine. I suspect you're attaching the script to the wrong thing: it must be attached to the target object, thus the variable something is not needed - you should destroy gameObject instead, which references the object itself:

var health = 60; // you don't need the "something" variable!

function OnCollisionEnter(thing : Collision) { if (thing.collider.tag == "Bullet") { health -= 1; } else if (thing.collider.tag == "FlameBall") { health -= 3; } else if (thing.collider.tag == "Bomb") { health -= 6; } // Debug.Log is more useful here: Debug.Log("Tag:"+thing.collider.tag+" Health:"+health); }

function Update () { if (health

Comment
Add comment · Show 7 · 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 sam32x · Oct 19, 2011 at 10:47 PM 0
Share

the scripts are attached right, the target has like 30 colliders and a rigidbody, the bullets have 1 child collider and a rigidbody, also in the hierarchy, the bullet that is colliding is called Bullet(Clone)

avatar image aldonaletto · Oct 20, 2011 at 01:32 AM 0
Share

30 colliders? Try with a simpler target - a cube, for instance - then increase the complexity to find what's causing the problem. I tested the script above attached to a simple cube, and the cube health decreased as expected when shot. I added another cube as a child, and it still worked as if both were a single body.

avatar image sam32x · Oct 20, 2011 at 06:32 AM 0
Share

i removed every collider except the parent collider and still the same result

avatar image sam32x · Oct 20, 2011 at 06:34 AM 0
Share

i skipped the update to 3.4 because my internet was dead and i have 3.3, how do i update?

avatar image sam32x · Oct 20, 2011 at 06:44 AM 0
Share

hmm, it just randomly started working

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Change Direction on Collision 6 Answers

get angular velocity change from collision 0 Answers

Collision with no contact? 2 Answers

script trying to access a null gameobject's collider... can't fix 2 Answers

WALL collision detection problem... help!!!! 0 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