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 icelated · Aug 26, 2012 at 12:51 AM · c#inheritanceclassesoop

FPS weapons class structure

Okay, i have been learning unity for a couple of months now here and there when i can. I am making a FPS. I have looked at examples from fps kit 1.2 and dastardly bananas code. Its clustered and hard to understand. I would like to approach this from an oop perspective.

I have 5 guns(AK47, M9 pistol, M16, HK-MP5, etc) that have arms attached with animations such as "show", "hide" , "reload" , "single shot" ,"multiple shot" , "zoom", "run" , etc animations.

So far, i have attached 2 guns to the first person controller that i will swap out when needed. I also want to drop and pickup weapons.

So, i have 2 questions and you can answer which one you like.

  1. are there any FPS game projects that use oop that i could download and learn from besides unity demos?

  2. In unity, would oop benefit me for a FPS game? if so could someone help me out with a weapons class structure?

This is what i was thinking.

    public class Weapon : Monobehavior  {
               fire
               reload
               ammo 
               play animation
               damage
               drop weapon
               pickup weapon
               }                //not sure what to put in the classes

Further,

 public class machineGun : Weapon

and

 public class machineGun : Weapon

It appears to me that oop will just complicate things? Thank you so much. Any help is much appreciated.

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 FatWednesday · Sep 07, 2012 at 10:46 PM

The only real reason to introduce polymorphism here would be if each of the guns had a different set of logic involved in playing the animations.

From the information you've provided, it seems like all the guns have each of the animations, the only thing that would be different, would be things like fire rate, damage, magazine size, etc. IF that's the case then these values can just be placed on your weapon class, and set to specific values for each different type of weapon (how you define and use those presets is up to you, be it a separate struct that's read in, or entire weapon classes serialized out to file. etc).

Hope this helps, if not some more information about the differences in how you want the guns to act might help.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

An OS design issue: File types associated with their appropriate programs 1 Answer

Calling a method of a class that is a part of another class? 1 Answer

Problem using variable of type CustomStat to indicate which player statistic to change 1 Answer

HideInInspector with inherited variables 1 Answer

Cram variables inside class, use inheritance, or something else? 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