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 danish114206 · Mar 05, 2013 at 03:35 PM · playeraireducehealth

how to make AI reduce PlayerHealth ??

Can anyone give me a script to make the A.I reduce the Player's Health??

this is my health script

PlayerHealth JS script

 static var curHealth : int = 100;
 static var maxHealth : int = 100;
 
 var healthtext : GUIText;
 
 static var curXp : int = 0;
 static var maxXp : int = 500;
 
 var xptext : GUIText;
 
 var level :int = 1;
 
 
 static var minAttack : int = 10;
 static var maxAttack : int = 50;
 
 static var attackPower : int = 2;
 
 
 
 function Start () {
 
 
 healthRegen();
 
 }
 
 
 
 
 
 function Update () {
 
 
 healthtext.text = curHealth + " / " + maxHealth;
 
 xptext.text = "Level " + level + " xp " + curXp + " / " +maxXp;
 
 
 if(curXp == maxXp) {
 
 
 levelUpSystem();
 
 
 }
 
 
 
 
 if(curHealth < 0 ) {
 
 curHealth = 0;
 
 
 }
 
 
 if(curHealth > maxHealth) {
 
 
 curHealth = maxHealth;
 
 
 }
 
 
 
 if(Input.GetKeyDown("e")) {
 
 curHealth -= 10;
 
 }
 
 if(Input.GetKeyDown("r")) {
 
 curXp += 10;
 
 }
 
 
 
 
 }
 
 
 
 
 function healthRegen () {
 
 
 for(i=1;i>0;i++) {
 
 
 
 yield WaitForSeconds(0.5);
 
 if(curHealth < maxHealth) {
 
 curHealth++;
 
 }
 
 
 }
 
 
 }
 
 
 function levelUpSystem () {
 
 
 curXp = 0;
 maxXp = maxXp + 50;
 level++;
 
 maxHealth += 50;
 
 
 
 
 
 }



========================================================================================= //

I try with This script ,BUT not work

 var cube : GameObject;
 
 function Awake()
 {
 cube = gameObject.FindWithTag("Player");
 }
 
 function OnCollisionEnter(hit : Collision)
 {
 if(hit.gameObject.tag == "cube")
 PlayerHealth.curHealth -= 20;
 }




========================================================================================= //

Please Assist :)

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 deltamish · Mar 05, 2013 at 03:38 PM 1
Share

hi i dont think i can read your script to fix this go to edit>select the code and press 101010 .by the way are you trying to reduce player health when you press a button

avatar image deltamish · Mar 05, 2013 at 03:54 PM 0
Share

@danish114206 Are you trying to reduce the Health of the player on button press(just spitballing) .Explain what you are trying to achieve so that i can post the script

0 Replies

· Add your reply
  • Sort: 

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

11 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

Related Questions

player to kill ai 0 Answers

NavMesh flee. Ai flee from player. 4 Answers

Need Help About Health,Damage 1 Answer

Script is only working on original object 2 Answers

Player Health 3 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