- Home /
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.
are there any FPS game projects that use oop that i could download and learn from besides unity demos?
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.
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.
Your answer
Follow this Question
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