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 splendidTRUSTe · May 26, 2014 at 06:03 PM · scalecollidehealth

Die on collision doesnt work

i have a code for health and in the code i have a code so i would die on collision with the enemy, the enemy has a riged body and my charector does too and we both have a charector.collider() or whatever it is but the code is not working please help! the code is:

 var PlayerHealth: float = 10.0;
 var EnemyDamage: float = 10.0;//(damage per sec)You may change it to kill player quickly
  
 function OnTriggerStay(enemy: Collider){
   if(enemy.CompareTag("Enemy"))
 {
  PlayerHealth-=EnemyDamage*Time.deltaTime;
 }
   if(PlayerHealth<0)
   {
     Debug.Log("Player died.You lost!");
     Destroy(gameObject);
   }
 }
Comment
Add comment · Show 6
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 LMan · May 26, 2014 at 06:13 PM 0
Share

The script is attached to the player gameobject yes? You would see it listed in the inspector. Also check that the enemy gameobject is tagged "Enemy" (it is caps sensitive!).

avatar image splendidTRUSTe · May 26, 2014 at 06:23 PM 0
Share

ya the gameobject is tagged "Enemy" and the script is attached to the player gameobject

avatar image tanoshimi · May 26, 2014 at 06:25 PM 0
Share

"...we both have a charector.collider() or whatever it is..."

Details like this matter a lot. If you're asking other people for help, please have the courtesy to put some effort in yourself and describe the scenario fully and accurately.

avatar image splendidTRUSTe · May 26, 2014 at 06:25 PM 0
Share

oh thanks it wasnt attached to the object it was attached to the controlles

avatar image splendidTRUSTe · May 26, 2014 at 06:31 PM 0
Share

but when i build the game my charector doesnt die it just keeps going!!!!

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by eshonbel · May 26, 2014 at 09:16 PM

Might as well try loading a new scene instead of destroying, you could load a level. 1. Make a level, call it Respawn 2. Change this:

 Destroy(gameObject);
 
 //to this
 
 Application.LoadLevel("Respawn");
 
 //and then add Respawn to build settings.
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 Java666 · May 28, 2014 at 09:40 PM

i think you are just missing a collider you need a physic collider and have it check if trigger in that collider if using a trigger function

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

24 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 avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Scale FPS character/view throws everything out of wack, help? 1 Answer

How to make blocks collide - help fast please 1 Answer

Damage script 0 Answers

Scavenger script woe... 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