Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 BL1TZ · Aug 12, 2015 at 11:13 PM · unity 5character

How to connect multiple stats scripts for the actual character stats?

Necessary information: I am making this RPG in unity using C# scripts. This RPG includes character stats, based on spendable stat points gained each level, but these character stats are also influenced by armour, character level, etc. So, my idea was to make different scripts which will get the stats for the different aspects, for example:

  1. A script which will "get" the stats of the armour the player currently wears

  2. a script which will "get" the stats of the weapon the player currently wears

  3. a script which will "get" the stats when the player gets a buff

  4. a script which will "get" all of the spend points in a stat

and so on.

Eventually these scripts all influence the actual stats of the player (lets say a hotkey "C" is pressed to lookup the character stats), so they must be connected together. Now my question is, how will I actually connect all those scripts in 1 script named: "calculate stats", so I can inherit from it using a script called: "actual stats". Will I have to use interfaces to inherit from them all? I hope my question is clear and somebody can give me a proper answer...

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by getyour411 · Aug 12, 2015 at 11:12 PM

Not an argument against "Inheritance" but there's nothing that dicates its a must here. The Armor class can call a method in the CalcStats class whenver armor is equipped, repaired, enchanted, removed,etc as can all the other external classes.

 Armor Class
 private CalcStat calcStat;
 
 Start()
 calcStat = GameObject.FindObjByTag("Player").GetComponent<CalcStat>();

(methods in Armor can call CalcStat)

 calcStat.BuffStrMod(10);
 calcStat.BuffDexMod(10);
 calcStat.weight = weight + item.weight;
 etc.


Comment
Add comment · Show 2 · 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 BL1TZ · Aug 13, 2015 at 12:18 PM 0
Share

Thank you so much for your reply! It didnt come to my $$anonymous$$d to tackle the problem this way, and I will definitely try this out :').

One little question though, do you have an example when I should use inheritance over the way u just described here? And if it does not bother u, could you give an example of the same problem solved with inheritance? I guess there are multiple ways to do it, but I often find it hard to make the right choice at the right moment and I'm curious what it will look like when inheritance is actually used...

avatar image getyour411 · Aug 14, 2015 at 03:07 AM 1
Share

Your question implies you aren't familiar with inheritance, that's why I suggested an alternate route which might make your code maintenance easier until you have picked that up. There are some good examples of potential Inheritance candidates in your post though. There's a good tut from Unity on the subject here

https://unity3d.com/learn/tutorials/topics/scripting

Intermediate / Inheritance (and Interfaces).

To go from Coder 101 to Coder 201, I highly recommend spending time with those vids.

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

2 People are following this question.

avatar image avatar image

Related Questions

Unity networking create & join with custom character?, 0 Answers

Rigidbody player keeps moving after AddForce has stopped? 3 Answers

Character selection 1 Answer

Cloth Component in Unity 5 1 Answer

How to use Animator Override Controler in script? 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