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
-1
Question by Rockstxr · Apr 09, 2015 at 04:30 AM · playerdeathrestartendhealth

How to add Player health and ability to take damage from a cube?

I need to know how to make my player which is the Unity model called "RollerBall" take damage from a sliding cube which are called "cube" and "pillar" on touch and/or make it end the game with an option to restart.

I'm new to all this stuff and could really use the help. I appreciate your time if you can help me. Whatever it is you can help me with, i really need you and again appreciate your time. Im willing to collaborate with anyone to make this a reality and happen if needed.

Thanks, Rockstxr

Comment
Add comment · Show 2
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 Digital-Phantom · Apr 09, 2015 at 10:54 AM 0
Share

Try looking at your question objectively. Breakdown the parts you want to accomplish and have a go at coding those smaller parts.

Then(if) you have any problems come here to ask for some help on a specific issue. Adding code and pictures to a question is also very helpful for people to understand your problem.

:)

avatar image Rockstxr · Apr 12, 2015 at 12:18 AM 0
Share

I don't know how to do damage and health,that's all i need. I have a ball that is the player and cubes sliding at it that it needs to dodge or else it will get killed if it touches one. PLAYER NA$$anonymous$$E= RollerBall / ENE$$anonymous$$Y NA$$anonymous$$E: Cube / ENE$$anonymous$$Y NA$$anonymous$$E: Pillar

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ForeignGod · Apr 09, 2015 at 10:17 AM

This isn't tested at all, it's just to show you how you can do it. Customize it to your needs

 #pragma strict
 var health: int;
 
 function Start ()
 {
 health = 100;
 }
 
 function OnCollisionEnter (col : Collision)
 {
     if(col.gameObject.name == "Pillar")
     {
         health-= 25;
     }
     if(health <= 0)
     {
         Destroy(gameObject);
     }
 
 }
 
 
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 Rockstxr · Apr 12, 2015 at 12:11 AM 0
Share

Thanks for your help, imma need to try that.

avatar image Rockstxr · Apr 12, 2015 at 12:30 AM 0
Share

Unity says: BCE0018: The name 'Int' does not denote a valid type ('not found'). Did you mean 'System.Int32'?

avatar image ForeignGod · Apr 12, 2015 at 12:39 AM 1
Share

Sorry, change Int to int.

avatar image Rockstxr · Apr 18, 2015 at 12:34 PM 0
Share

Ok, that solved the complier error thanks

avatar image
0

Answer by Kaz_Yamof · Apr 09, 2015 at 10:36 AM

Is impressive how people ask things so generic here. I mean... "How to receive damage?" You tell me, it's your game with your rules, you should be able to imagine them.

Try to be more specific: "How comunicate between two scripts?" or "How show the damage received on a lifebar?" or "How detect the end of a collision?"

This doubt is a very basic flaw in your coding skill, try start getting better on coding before learning Unity. Answer: You need to create your rule system. How much life the player has? How the damage is calculated: by weapon? by enemy? the player has an armor to defense himself? This is game design, and you need to have an ideia about how your game will be first. Supose that you have an Player with an armor, and an Enemy with an weapon, let's make the following:

  • Class name -> Player

  • Fields (define a value to each field as you want):

  • life -> int

  • maxLife -> int

  • minLife -> int

  • armor -> int

  • Class name -> Enemy

  • Fields

  • life -> int

  • maxLife -> int

  • minLife -> int

  • weapon -> damage

Now you will check how collision detection works. And in the collision method you subtract the life by enemy weapon plus armor.

This way your cube is receiving damage. But what goes when the life is zero? You will need to kill the cube, or do something else.

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 Digital-Phantom · Apr 09, 2015 at 10:51 AM 0
Share

@daybson.paisante there is little point be patronising to the OP, simple directive answers to some helpful threads or tutorials would have been better.

However in your defence, you are correct, the question is very vague and to be honest should not have been accepted onto the UA. A moderator should have declined the post and directed the OP in his search.

:(

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Player Will not take any damage! 1 Answer

Death scene/screen on player Health Script Wont work! 0 Answers

I need help with the player's health points 1 Answer

Damage script is screwed up...? what to do? 1 Answer

c# how to change player location on 0 hp 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