Quantcast
Channel: Questions in topic: "item"
Viewing all articles
Browse latest Browse all 274

Class inheritance for Item system question: Instance needs to be both Weapon and Ammo subclass

$
0
0
I have three classes: a base Item class as well as two classes inheriting from it: Weapon and Ammo. public class Item { public string name; public Texture2D icon; } public class Weapon : Item { public int ammo_max; public int damage; } public class Ammo : Item { public int amount; } So far, so good. Now my problem: I want to have grenades that can be both: Weapon and Ammo. They could be loaded as Ammo for a grenade launcher (Weapon) or they could be a Weapon themselves (thrown). Is there an elegant way of accomplishing this, or have I walled myself in with my item inheritance? :)

Viewing all articles
Browse latest Browse all 274

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>