Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by Jack Eaves · Apr 21, 2010 at 09:22 AM · enemydamagenpckillhealth

How to create an NPC enemy which can take damage and be killed when its energy or health reaches zero?

Hi, I am a student who wants to create a 'RPG' style 1 level game for my Final Major Project at college. We have no teachers in the college with knowledge of Unity and its the first time using it myself, I have managed to teach myself how to attach animation to keys (for walking etc) and create a controllable 3rd person character.

However I would like to know how to create a killable NPC enemy character?

Any help would be great, thanks!

Comment
Add comment
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

2 Replies

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

Answer by Not showing my name · Apr 21, 2010 at 12:07 PM

Go to

unity3d.com

and then click to support, then resources, and then fps tutorial. download the completed thing and then get "Damage Receiver [Script]"

here's the link DIRECTLY TO THE DOWNLOAD.

http://unity3d.com/support/resources/tutorials/fpstutorial

Awesome question!

Comment
Add comment · Show 4 · 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 Not showing my name · Apr 21, 2010 at 12:51 PM 0
Share

Plus, you can make a ragdoll of the character so when it's destroyed it collapses.

avatar image user-2235 (google) · Apr 21, 2010 at 02:35 PM 0
Share

Thank you! this tutorial looks like it will be a great help in more than just this aspect of the game, going to get stuck into it. Thanks again.

avatar image Not showing my name · Apr 22, 2010 at 05:16 PM 0
Share

you're welcome. I made a game called "High Security jail cell remake and you have 2 guns: a machine gun and a rocket launcher.

avatar image taironcz · Nov 15, 2019 at 05:40 PM 0
Share

error 404 help please

avatar image
1

Answer by duck · Apr 21, 2010 at 09:40 AM

At a very basic level, you'd need to have a script on your NPC which has a variable containing its current amount of health, and a function which is designed to be called by other weapons or hazards, which reduces this health value.

This function would then be responsible for reducing the health value, and killing and removing the NPC when its health reaches zero.

For example:

var health = 100.0;

function ApplyDamage( amount : float ) {

 health -= amount;
 // <- (update on-screen health displays here)

 if (health < 0) {
     Die(); 
 } else {
     // <- (play "hurt" animation & sound here)
 }

}

function Die() {

 // <- (play "die" animation & sound)

 yield WaitForSeconds( dieDuration );

 // now remove this gameObject from the scene:
 Destroy(gameObject);

}

Comment
Add comment · Show 1 · 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 Jack Eaves · Apr 21, 2010 at 09:59 AM 0
Share

Thanks you for the quick and helpful reply, much appreciated! I will give this a shot while at college and see how i get on with it, thanks again.

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

1 Person is following this question.

avatar image

Related Questions

Health below zero but shows negative numbers 1 Answer

Object Not Recieving Damage 3 Answers

One enemy triggers all the enemies 2 Answers

Problem with enemy health. 1 Answer

The enemy don´t lose health, but why??? 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