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 mkjrfan · Dec 22, 2013 at 03:23 PM · collisiononcollisionentercollisions

OnCollision Works for one script but not the other?

Hi, I've been trying really hard to get this part of the script to work but I just don't understand why it wont work here are my scripts:

The one that works:

 void OnCollisionEnter (Collision other)
     {
         print("hit");
         if (other.gameObject.tag == "Bullet")
             health -= 1;
     }
 

The one that doesn't:

 void OnCollisionEnter (Collision other)
     {
         print("hit");
         if (other.gameObject.tag == "Player")
             Destroy(gameObject);
     }
 

What I did was put both of these scripts into one object and let the player just run into it. It prints out "hit" only for the first script but not the second. I took out the first script and when testing it again no hit is printed.

I have boxcolliders in both of my objects and 2 rigidbodies. One stands still the other (the player) runs into it.

I do not understand why the second script prints nothing. Any ideas?

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 KellyThomas · Dec 22, 2013 at 03:28 PM 0
Share

Are both scripts active i.e. the little tickbox in the inspector is ticked?

avatar image mkjrfan · Dec 22, 2013 at 03:30 PM 0
Share

Yes both were active. But I did notice something weird when i deactivated the 1st script it was still ran.

avatar image KellyThomas · Dec 22, 2013 at 03:32 PM 0
Share

If in doubt add a print statement to both script's Start() method.

avatar image mkjrfan · Dec 22, 2013 at 03:34 PM 0
Share

Okay so I did that to the fist script and it doesn't print the start function but does print out hit still.

avatar image KellyThomas · Dec 25, 2013 at 03:44 PM 0
Share

If Start() is not running but other methods are, it sounds like "Start" might be misspelt or have the wrong parameter signature.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tekksin · Dec 25, 2013 at 07:58 AM

     void OnCollisionEnter (Collision other)
     {
     
     if (other.gameObject.tag == "Player")
     Destroy(gameObject);
     print("hit");
     }

I don't really script like you do. I just do "function OnCollisionEnter (other: Collision){}" It may not be saying anything because you don't have it in the event brackets for if(other.gameObject.tag == "Player"){}.

Aside from that, just make sure the tags are right.

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 mkjrfan · Dec 22, 2013 at 04:25 PM

Is there really no solution to this? Has anyone else had this problem before?

Comment
Add comment · Show 2 · 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 Josh707 · Dec 22, 2013 at 08:50 PM 0
Share

Perhaps the second script is not on the object with the collider?

avatar image mkjrfan · Dec 23, 2013 at 01:57 AM 0
Share

No, sorry they are both on the same objects with a collider and rigidbody.

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

21 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

Related Questions

Ammo crate collision 2 Answers

Dictionary with GameObject as key is updating values under other keys 1 Answer

Quad mesh collider detects side collisions when it should not 0 Answers

Delayed Collisions Bug (includes video demonstration) 1 Answer

Boo & Collision 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