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 /
This question was closed Nov 17, 2014 at 06:02 PM by Jeff-Kesselman for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by harry510 · Nov 17, 2014 at 04:36 AM · collisionzombies

Problems with Collision

Hi I'm having probems with the collision on my zombie, here is the code for the collision.

 var curHealth : int = 100;
 var maxHealth : int = 100;
 function OnCollisionEnter(hit : Collision) {
 if(hit.transform.name == "ZOMBIE") {
 curHealth -= 3;
 Debug.Log("ok");
 }
 }
 var healthtext : GUIText;
 var regenActive = true;
 function Start () {
         healthRegen();
 }
  
 function Update () {
  
         healthtext.text = curHealth + " / " + maxHealth;
  
         if(curHealth < 0 ) {
                 Application.LoadLevel("NewOne");
         }
  
         if(curHealth > 100) {
                 curHealth = 100;
         }
  
         if(Input.GetKeyDown("e")) {
                 curHealth -= 101;
         }
 }
  
 function healthRegen () {
  
         while(regenActive==true) {
                 yield WaitForSeconds(0.5);
  
                 if(curHealth < maxHealth) {
                         curHealth++;
                 }
         }
 }

The zombie has a box collider, but when I touch it my health doesn't go down, do I need change the propertes of the zombie or the actual script?

Comment
Add comment · Show 3
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 tanoshimi · Nov 17, 2014 at 06:59 AM 1
Share

This question has been asked many, many times. Please confirm that you have already investigated and followed the most common solutions:

  • Is this script actually attached to your player gameobject in the scene?

  • Do both parties involved in the collision (i.e. the zombie and the player) have colliders attached?

  • Are the colliders marked with IsTrigger off?

  • Does at least one of either the zombie or the player also have a non-kinematic rigidbody component attached?

  • Is the zombie object called ZO$$anonymous$$BIE in the hierarchy? (And not, for example, ZO$$anonymous$$BIE (Clone), if instantiated from a prefab)

avatar image richyrich · Nov 17, 2014 at 10:13 AM 0
Share

Please also format the code properly, so that it is easier to see what is going on

avatar image harry510 · Nov 17, 2014 at 06:02 PM 0
Share

Sorry, I was looking through other scripts and found the answer. Anyways thank you for your contribution!

1 Reply

  • Sort: 
avatar image
0

Answer by Ayr · Nov 17, 2014 at 10:14 AM

Make sure you attach a rigid body to your object as well if your using Collision be sure to have trigger unchecked on the collider. Sorry c#

GameObject ZOMBIE;

 void OnCollisionEnter(Collision collision) {
         
         if(collision.gameObject.name == "ZOMBIE") 
         {
             curHealth -= 3;
             Debug.Log ("curHealth");
         }
 }
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

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Trying to Disable Compenent when there's a collsion 2 Answers

Detect Collision in an If Statement? 1 Answer

Don't restart music on death 2 Answers

Changing terrain texture on contact (collision) 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