I will offer an example, since I’m tired of re-writing it multiple times, and will leave the answers open in case someone has a better way
*Also note that this is an example, mostly generalized…
public class Master : MonoBehaviour
{
public static List<Player> players = new List<Player>();
public static List<Item> items = new List<Item>();
public static List<Weapon> weapons = new List<Weapon>();
}
public class Player : Master
{
Weapon myWeapon;
Item currentItem;
Player myEnemy;
public List<Weapon> myWeapons = new List<Weapon>();
public List<Item> myItems = new List<Item>();
public List<Player> myEnemies = new List<Player>();
void Awake()
{
players.Add(this);
}
void OnCollisionEnter(Collider other)
{
if (other.gameObject.CompareTag("Weapon")) // set tags in inspector
{
for (int i = 0; i < weapons.Count; i++)
{
if (other.gameObject == weapons*.gameObject &&*
_ !myWeapons.Contains(weapons*))_
_ {_
_ myWeapons.Add(weapons);
return; // stop the loop from thinking*
* }
}
}
}*_
* void FindGreatestWeapon()*
* {*
* for (int i = 0; i < myWeapons.Count; i++)*
* {*
_ if (myWeapons*.damage > myWeapon.damage)
{ myWeapon = myWeapons; return; }
}
}*_
* void BuyItem(int affordCost)*
* {*
* for (int i = 0; i < items.Count; i++)*
* {*
_ if (items*.costValue == affordCost &&
!myItems.Contains(items))
{
myItems.Add(items);
return;
}
}
}*_
* void AttackPlayer(Player enemy)*
* {*
* enemy.health -= myWeapon.damage;*
* }*
}
public class Item : Master
{
// General variables used by all items
public int costValue;
// General functions used by all items
}
public class Potion : Item
{
* void Awake()*
* {*
* costValue = 25;*
items.Add(this);
* }*
}
public class Weapon : Master
{
// General variables used by all weapons
public int damage;
* // General functions used by all weapons*
}
public class Sword : Weapon
{
* void Awake()*
* {*
damage = 50;
* weapons.Add(this);*
* }*
}