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 WesterlyCarrot9 · Jan 25, 2014 at 05:31 AM · c#javascriptcharacterrpgstatistics

Character Attributes Question

Hello! So i've made the below script which shows the attributes of a character. What i basically wanna do is to increase the HealthPoints by 10 for every 2 Vitality points so it would be 50 HP for 10 Vitality. Like i did it with the "for" function it is 100 HP. Of course, the other thing i want is about the GUI Button. I want to have the HealthPoints increased by 10 but again for every 2 Vitality Points so it would be for 12 points you get +10 Health and so on. Could you help me a bit? Thanks!

 var STRENGTH : int;
 var DEXTERITY : int;
 var INTELLIGENCE : int;
 var VITALITY : int;
 
 var HEALTHPOINTS : int;
 
 function Awake(){
     STRENGTH = 12;
     DEXTERITY = 9;
     INTELLIGENCE = 8;
     VITALITY = 10;
 }
 
 function Start(){
     for(var i : int = 0; i < VITALITY; i++){
         HEALTHPOINTS += 10;
     }
 }
 
 function OnGUI(){
     stat1 = "Strength : " + STRENGTH;
     stat2 = "Dexterity : " + DEXTERITY;
     stat3 = "Intelligence : " + INTELLIGENCE;
     stat4 = "Vitality : " + VITALITY;
     stat5 = "Health : " + HEALTHPOINTS;
     GUI.Box(new Rect(20,20,100,70),stat1 + "\n" + stat2 + "\n" + stat3 + "\n" + stat4);
     GUI.Box(new Rect(140,20,100,40),stat5);
     if(GUI.Button(new Rect(20,100,40,20),"+")){
         VITALITY += 1;
     }        
 }

 
Comment
Add comment · Show 9
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 getyour411 · Jan 25, 2014 at 05:39 AM 0
Share

take vitality div 2, throw away remainder and multiply by 10

avatar image WesterlyCarrot9 · Jan 25, 2014 at 05:42 AM 0
Share

Could you write it more clearly please? :P

avatar image WesterlyCarrot9 · Jan 25, 2014 at 05:48 AM 0
Share

Would it be possible to change the code a bit and post it here? :P

avatar image getyour411 · Jan 25, 2014 at 05:53 AM 1
Share

I had it a little backwards in the first post anyway, you want to know if vitality has been increased by 2 and only then grant a new point in health is that right? so you want to do something like X % 2 and if the remainder IS zero, then it's gone up by 2

avatar image WesterlyCarrot9 · Jan 25, 2014 at 05:54 AM 0
Share

Oh never$$anonymous$$d sir i actually did it. Thanks a lot! But what about the other thing with the button? Hmm..

Show more comments

1 Reply

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

Answer by HappyMoo · Jan 26, 2014 at 04:40 AM

Hi,

you need to change your design, so the rules can be evaluated every time something changes.

 var baseSTR : int;
 var baseDEX : int;
 var baseINT : int;
 var baseVIT : int;
 var baseHP : int;
 var baseMP : int;
 
 var STRENGTH : int;
 var DEXTERITY : int;
 var INTELLIGENCE : int;
 var VITALITY : int; 
 var HEALTHPOINTS : int;
 var MANAPOINTS : int;
 
 function Awake(){
   baseSTR = 12;
   baseDEX = 9;
   baseINT = 8;
   baseVIT = 10;
   baseHP = 5;
   baseMP = 0;
   recalculateStats();
 }
 
 function recalculateStats()
 {
   STRENGTH = baseSTR;
   DEXTERITY = baseDEX;
   INTELLIGENCE = baseINT;
   VITALITY = baseVIT;
   ..
   // check for stats in/decreasers here, e.g.:
   //if (WearsRingOfDexPlusTwo) DEXTERITY = DEXTERITY + 2;
   ..
   HEALTHPOINTS = baseHP + 10*(VITALITY/2);
   MANAPOINTS = baseMP + 10*(INTELLIGENCE/2);
 }
 
 function OnGUI(){
     stat1 = "Strength : " + STRENGTH;
     stat2 = "Dexterity : " + DEXTERITY;
     stat3 = "Intelligence : " + INTELLIGENCE;
     stat4 = "Vitality : " + VITALITY;
     stat5 = "Health : " + HEALTHPOINTS;
     GUI.Box(new Rect(20,20,100,70),stat1 + "\n" + stat2 + "\n" + stat3 + "\n" + stat4);
     GUI.Box(new Rect(140,20,100,40),stat5);
     if(GUI.Button(new Rect(20,100,40,20),"+")){
        baseVIT += 1;
        recalculateStats();
     }  
 }  
Comment
Add comment · Show 8 · 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 WesterlyCarrot9 · Jan 26, 2014 at 05:13 AM 0
Share

WoW! That's a really nice system you posted there! :O Thanks a lot! I tried that out but for some reason when i press the + button nothing happens...I'm thinking about it right now.

avatar image HappyMoo · Jan 26, 2014 at 02:51 PM 0
Share

Oh wait, yes... actually pressing a button doesn't fit into the system, because it's not some kind of powerup... just to see that it's working, change the base when you click. I'm changing the code above

avatar image WesterlyCarrot9 · Jan 26, 2014 at 10:30 PM 0
Share

Yeah i experimented a bit with it myself and figured it out XD Thanks a lot! Obviously, if i want to do something similar with the rest of the stats, i'll do it like this right? I also have one more question. Would it be possible to make HealthPoints increase randomly? Sometimes 10 or 7 or 9 or whatever. To have a bigger variety and not just be 55,65,75 etc.

avatar image HappyMoo · Jan 27, 2014 at 03:00 AM 0
Share

Usually you handle something like this in the base values

 baseVIT = Random.Range(8,13);

These can also be different depending on race etc...

avatar image WesterlyCarrot9 · Jan 27, 2014 at 03:10 AM 0
Share

Hmm it still increases by 10 though.

Show more comments

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

19 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 avatar image avatar image

Related Questions

Simplest way for some stat presets for RPG classes? 1 Answer

Creation of RPG Class Stat Presets? 1 Answer

How do you make RPG class stat presets? 1 Answer

Basic Movement on a Plane without Character Controller 2 Answers

Multiple Cars not working 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