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 Swiftpaw · Sep 14, 2012 at 09:42 AM · inheritancedictionarytype

Configurable weapon system: assigning instances of varying types at runtime

I'm working on a configurable weapon system that takes three parts: a fire pattern(an arc like a shotgun blast, three projectiles in a row, circluar pattern etc.), an ammo type (bullet, rocket, cheese etc.) and a weapon mod, which overwrites things like damage or rate of fire. I thought it would be a fairly simple task but i'm running into problems. I must be still half asleep or something...

My initial design is to have a ConfigurableWeapon class that has three fields: pattern, ammoType and mod. These fields are types of abstract class that you would inherit from for individual ammo types etc. The user would pick what they wanted from a list, then when the game starts the weapon would be set up. Also, the A.I. controlled enemies would use the same system, with pre-specified settings per enemy prefab.

I thought I would use a static helper class that has a dictionary that stores an enum as a key, and the type to be added as a value, then return new instances as needed but I can't for the life of me get anything working this morning!

There's probably a more elegant way of doing this, or i'm overlooking something obvious, so any suggestions would be appreciated.

I can post the code if needed, but seeming as i'm still trying to figure out the design it's mostly just abstract class definitions and some inherited testing classes.

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
0

Answer by Swiftpaw · Sep 14, 2012 at 01:27 PM

Alright so after some lunch and caffeine I took another look at my design and decided I was doing it backwards. What I've done now is rather than trying to pull instances into the weapon when fired, instead store the firing patterns in a static dictionary in a manager class and using enums stored in the weapon, look up the appropriate pattern and pass it a reference to an ammo type stored in a different dictionary (also in the manager class) to be instantiated. Works so far, if a little obtuse.

I'll leave this up as an answer for now but if anyone has a more elegant way, i'd be interested in hearing it!

Thanks for your help Fattie, I decided to just go with prefab ammo types for simplicity, makes things easier in that regard.

Now I just need to add the weapon mod part and I can start blowing things up in all manner of entertaining ways!

Comment
Add comment · 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

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

10 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

Related Questions

Is script a child of another certain script? 1 Answer

List of Different Classes That All Inherit From One Class 1 Answer

typedefing in unity 1 Answer

I need an Array of System.type[] from all of my ScriptableObjects scripts 0 Answers

An OS design issue: File types associated with their appropriate programs 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