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
0
Question by Leonard Kropf · Apr 18, 2010 at 07:13 PM · live

life system.....

ok guys a big question

i want to make a live system

i have different weapons with a var called damage

now i want that if my Character is hit there should be a var that is reduced with every hit and than there should be a number in the game view in the corner that is maybe 100 and with every hit it will be reduced

and the final thing is that if different parts of my character are hit there should be more or less damage

i hope you can help me

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by spinaljack · Apr 18, 2010 at 08:10 PM

Download the 3D Platform tutorial There's a section for taking damage, storing lives and health, regaining health and respawning.

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 Peter G · Apr 18, 2010 at 09:40 PM

You basically want to have a function that applies damage on the character and have the enemy call that function.

A script like this goes on the enemy:

var damage = 10;

function OnCollisionEnter (col : Collision) { if(col.gameObject.CompareTag("Player") { col.gameObject.BroadcastMessage("ApplyDamage", damage, SendMessageOptions.DontRequireReciever); } }

Then something like this goes on your player.

var health = 25;

function ApplyDamage (damage : int) { health -= damage;

  if(health <= 0) {
       Die ();
  }

}

function Die () { Respawn ();

}

Now causing your player to take more or less damage at different spots is a little more complicated.

I would put colliders on the player in several smaller parts ie. the head and body. So the head collider is on the head gameObject and the body is on the root object. Then have the enemy find the tag of the object it hit and if it is a special part like the head, you would send a different damage in the Message.

var player = GameObject.FindWithTag("Player"); //Find the player so that if we hit the head we can still apply damage to the player. var headDamage = 25;

if(col.gameObject.CompareTag("Head") { player.BroadcastMessage("ApplyDamage", headDamage, SendMessageOptions.DontRequireReciever); }

//add the top script in appropriately.

P.S. I haven't tested the script so there might be a typo or two.

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 duck · Apr 18, 2010 at 09:51 PM

Here's a question and answer which discusses how you can adjust a numeric variable, and display that value on-screen:

How to increment a global counter variable (eg, a hit tally) and display in a GUIText

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

No one has followed this question yet.

Related Questions

Unity Live Help 1 Answer

Create an avatar to use when broadcasting live,How to use an avatar on webcam 0 Answers

Blend tree 2d platformer jump 5 Answers

How to embed live streaming video content into unity player (android) 1 Answer

GUI Live Counter - Accessing another script 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