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 Apr 19, 2013 at 04:06 PM by AlucardJay for the following reason:

Other : OP is asking for scripts.

avatar image
0
Question by TylerTimoJ · Mar 12, 2013 at 10:20 PM · playerenemycollidezombiehealth

Player Health

I am making a game where I have a player tagged "Player" and an enemy tagged "enemy". I want to deduct health away from the player so that the player dies in 10 seconds. health will be deducted from the player when he collides with the enemy. I just need a script for the player as I all ready have a script to handle killing they enemy.

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 Benproductions1 · Mar 12, 2013 at 11:25 PM 0
Share

Are you asking: Can you make me this? or are you asking: How do I make this?

avatar image Auggie · Mar 13, 2013 at 12:22 AM 0
Share

try using coroutine. are you using c# or js?

avatar image TylerTimoJ · Mar 13, 2013 at 01:50 AM 0
Share

I am using java, however I need my project done soon and I don't have time to learn java. can someone write it?

avatar image PikaSaiyan · Mar 13, 2013 at 01:59 AM 0
Share

Why not just search for a tutorial ins$$anonymous$$d of asking for someone to make it for you? Anyways, here's a good one. http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial. I know it's in C#, but all you'll need to change really is the variables and add function(). Or, you could just use C# since I doubt you have much scripted.

avatar image Unitraxx · Mar 15, 2013 at 02:23 AM 0
Share

Java is something completely different, don't look for tutorials on that.

3 Replies

  • Sort: 
avatar image
0
Wiki

Answer by DryTear · Mar 13, 2013 at 01:53 AM

in Javascript;

 var cTime : Int = 10f;

 function OnTriggerEnter(me : Collider)
 {
     if(me.gameObject.tag == "Player")
     {
         yield WaitForSeconds(cTime);
         Destroy(me.gameObject);
     }
 }
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 TylerTimoJ · Mar 14, 2013 at 03:46 AM 0
Share

What do I replace "me" with?

avatar image DryTear · Mar 15, 2013 at 03:06 AM 0
Share

u dont need to change it - it works fine

avatar image
0

Answer by Auggie · Mar 15, 2013 at 05:51 AM

here:

 var health = 10;
 var i; 
 function OnTriggerEnter( something : Collider )
 {
    var timer=10;
  
    if(something.gameObject.CompareTag("Enemy"))
     {
          for ( i= 0; i < timer; i++){
          health--;
          yield WaitForSeconds(1); 
     //this will deduct 1 health per second for 10 seconds
         }
     }
 }
 function OnTriggerExit( something : Collider )
 {
     i = 10;
 }


again. add this to the player and add rigidbody to both player and enemy.

please upvote so that we'll be done here.

Comment
Add comment · Show 5 · 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 Tarlius · Mar 15, 2013 at 07:48 AM 1
Share

This is a kinda unsafe way to do this, by the way. Consider what happens if you collide with two enemies, then stick like glue to one but move away from the other.

Also note that you aren't checking what it is you're moving away from.

avatar image Auggie · Mar 15, 2013 at 08:14 AM 1
Share

true. it's not a fool proof code. it's just a skeleton. i made it as simple as i can and as quickly as i can...hehehe...it's just to get him started

avatar image Tarlius · Mar 15, 2013 at 08:19 AM 2
Share

Since he's asking for people to do his homework he probably doesn't care anyway, right? $$anonymous$$ake him work for his A! >:D

avatar image Auggie · Mar 15, 2013 at 09:20 AM 1
Share

something like that...hehehe

avatar image ExpiredIndexCard · Apr 19, 2013 at 01:54 AM 0
Share

lol do it yourself because this site is for questions not for homework answers. Learn

avatar image
0

Answer by nixcs2512 · Mar 15, 2013 at 09:16 AM

here in JS:

 var PlayerHealth: float = 10.0;
 var EnemyDamage: float = 1.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);
   }
 }

Remember to add Rigidbody to your character.

Comment
Add comment · Show 5 · 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 TylerTimoJ · Mar 16, 2013 at 01:03 AM 0
Share

Thanks for not being such a jerk like everyone else. you can't learn Javascript without the help of people like you. The way you wrote it makes perfect sense. Thanks a ton bro!

avatar image Auggie · Mar 18, 2013 at 12:31 AM 0
Share

ouch! that just hurts...

avatar image teresio · Apr 18, 2013 at 02:37 PM 0
Share

What has to happen? I added it, and the enemy just came to me, and circled around me, nothing happened...

avatar image Auggie · Apr 19, 2013 at 12:18 AM 0
Share

that's basically what it does. but when your playerhealth becomes zero a message in your debug console will say: "Player died. You Lost!"...you need to add something else in the: if (PlayerHealth<0) { //add code here to make me do something. }

to make is do something. afterwards, the player object will be destroyed.

avatar image Benproductions1 · Apr 19, 2013 at 02:14 AM 0
Share

@Tyler$$anonymous$$J The only person being a "Jerk" here is you! For expecting an answer for a question that doesnt not fit the requirements posed by UA. You are the "Jerk", because you expect to learn without putting in any effort what so ever yourself. You can't learn JavaScript by just reading other peoples code! DO IT YOURSELF!!

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Player Character Health 2 Answers

Enemy not taking damage on collisions. 2 Answers

Taking a hit 3 Answers

Getting enemy to move towards player untill they collide problem... 2 Answers

Lose health on 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