Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Frozaken · Aug 02, 2016 at 05:15 PM · classscriptableobjectclassesinterfaceinterfaces

storing scripts that implements an interface

I have a scriptable object set up to store all information on the items in my game, however some of my items will be usable and i still want to store them in my scriptable object. I made an interface called IUsable and i hoped i could somehow reference scripts that implemented that interface in my item class, something along the line of

 Public IUsable Scriptiwanttostore

so i could just make a script for each item which could be used and then use that script as a variable for each.

is there a way to do this? or should i go about it in another way?

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 Spider_newgent · Aug 02, 2016 at 06:10 PM 0
Share

Not sure whether it's just me, but your question seems a little unclear.

Wouldn't the declaration you've written type Scriptiwanttostore as a seperate instance of your interface IUsable? I'm not sure why you'd want to do that.

The way I'm reading your question is that you want a container to store a reference to all objects, whether they have been used or not. If that's the case, the following link is a great reference:

http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type

If you're asking something else, you might want to re-word the question.

Dan

avatar image Frozaken · Aug 02, 2016 at 09:10 PM 0
Share

im sorry if it was worded poorly, what im trying to achieve is a way to call diffrent functions, depending on which item i use, basicly i want an effect on each diffrent item i use, how should i store these diffrent functions, so they are connected with my diffrent items?

avatar image Spider_newgent Frozaken · Aug 03, 2016 at 07:20 AM 0
Share

You could create a Class called Item to store common properties like name, inventorySprite, value and so on. Then create other classes for Armour, Weapon, Potion and so on which inherit from Item. Each of the Armour/Weapon/Potion etc could have their own functions. You could then have a list or array of type Item to hold all the objects you create.

This would allow you the flexibility to create a +2 Bronze Broadsword of Goat Herding, different health potions, plate mail, chain mail, scale mail, leather jerkins and so on.

I'm still not sure I'm answering your question properly? Can you tell me what items you're using and what actions you want the functions to carry out?

Dan

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

52 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 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 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

Interface on ScriptableObject 1 Answer

All interfaces in one Script 1 Answer

Getting a slider's width to match the size of the group it's in? 1 Answer

Access class variables of selected object 1 Answer

Unity C# Start function without extending Mono 2 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