Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- public class Weapon {
- //make dictionary of soldiers and weapons
- private Dictionary<Soldier, string> weaponsDictionary = new();
- public void AddToDictionary(Soldier key, string value) {
- weaponsDictionary.Add(key, value);
- }
- public void RemoveFromDictionary(Soldier key) {
- if (weaponsDictionary.ContainsKey(key)) {
- weaponsDictionary.Remove(key);
- } else {
- Debug.LogError($"The key {key} does not exist in the dictionary");
- }
- }
- public int CountTheDictionary() {
- return weaponsDictionary.Count;
- }
- public string GetWeaponsDictionary() {
- string contents = "";
- foreach (KeyValuePair<Soldier, string> kvp in weaponsDictionary) {
- contents += kvp.Key + ": " + kvp.Value + "\n";
- // Debug.Log($"Key = {kvp.Key} Value = {kvp.Value}");
- }
- return contents;
- }
- public void ShowAllDictionaryValueInfo() {
- foreach (KeyValuePair<Soldier, string> kvp in weaponsDictionary) {
- Debug.Log($"Key: {kvp.Key}, Value: {kvp.Value}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement