• 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 Tristsin · Mar 08, 2013 at 06:48 AM · javascript

Items with Statistics(such as attack damage) that actually effect the character?

I have a list of all of my items, now I just need to provide functionality to those items when they are equipped. Is there a simple way of giving those items functionality, such as a Short Sword that has 1 Pound of Weight, +5 to attack damage and actually having that attack damage be added to my character's damage when he has that weapon equipped?

(The only way I can fathom is creating a function for EACH item, and being that there are about 300 items, that sounds like not such a simple way, so before I jump into that I would like to know if there's a simple method I'm overlooking)

Comment
Add comment · Show 3
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 hoy_smallfry · Mar 08, 2013 at 06:48 AM 1
Share

Are you familiar with the idea of class inheritance?

avatar image Tristsin · Mar 08, 2013 at 06:53 AM 0
Share

I am indeed

avatar image hoy_smallfry · Mar 08, 2013 at 07:09 AM 0
Share

Well, I may have be misunderstanding your question, but it seems that this can be solved with class inheritance.

Unityscript supports class inheritance, like this explains. I mainly code in C#, so perhaps somone else can fill you in on any gotchas

2 Replies

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

Answer by Kiloblargh · Mar 08, 2013 at 07:35 AM

You don't need a function for every item. It would be simple enough to have a script on every item, and make it be the same one script, (attached to the prefab) with inspector-settable fields for every possible effect an equipped item can have, and if the item does not affect that attribute, you just leave it set to zero. Then the various action functions in your player's script add up the relevant variables to that action from all the players' equipped items.

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 Tristsin · Mar 08, 2013 at 07:39 AM 0
Share

Brilliant. Thank you. This was pretty much exactly what I was looking for, and normally the kind of simple solution I overlook.

avatar image Tristsin · Mar 09, 2013 at 04:03 AM 0
Share

Not sure if you'll even check to get back to me on this, but using this method, how do I go about adding these prefabs into my active inventory list?

avatar image
0

Answer by Ryzokuken · Mar 08, 2013 at 07:01 AM

An easy way of providing them with different specific damages is to use a health bar just like hack and slash rpg

and attaching a script named something like damage to each weapon where you import the adjustCurrentHealth or any similar variable and make it public so you can adjust it different for each weapon...

What it does is adjust the adjustment or damage it does to the enemy health, so each weapon can have a different attack damage

HOPING IT SOLVES YOUR PROBLEM,

~FORSAKEN

Comment
Add comment · Show 3 · 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 Tristsin · Mar 08, 2013 at 07:08 AM 0
Share

While this does seem like a viable option, I'm looking for some kind of simple method I've just not thought of, or have overlooked. This sounds like a working method, but I have items such as chestpieces that add weight, armor, magic resistance, health, etc, etc. and it seems like an overly-complex way of going about it. Again, maybe that's just how it's done but with most things I've learned with Unity, and scripting, is there's always a method I've overlooked that simplifies things. Like when I learned how to use interfaces. What a saver that is.

avatar image Ryzokuken · Mar 08, 2013 at 07:24 AM 0
Share

For making that, you need a more complex player affecting system where many more things matter than just sheer health...

As to having magic, I think that a mana or spirit bar just like health bar can be easily created and different scripts attached to your player where pressing a button would create a spell which decreases your mana and target's health by a constant value.

Or you can make the values public and attach the same script for each magic but the value of mana cost and damage can be adjusted in the GUI.

avatar image Tristsin · Mar 08, 2013 at 07:41 AM 0
Share

Good ideas, again, but another person ($$anonymous$$iloblargh) gave me a very simple and effective solution above. Thank you for your help, though.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Multiple Cars not working 1 Answer

Sorting through the same variable attached to several GameObjects from least to greatest, then returning an enum state based on that order 0 Answers

Randomly Generated Objects 1 Answer

Need help with my script 0 Answers

Attach object as child using code 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