public void takeArmour(int level) { //go through the list of saved armours for (int i = 0; i < armourList.playerArmour.Count; i++) { //if the armour matches the one chosen if (armourList.playerArmour[i].level == level) { //set it as current armour currentArmour = armourList.playerArmour[i]; currentArmourIndex = i; //change it in the other script GameObject playerArmour = GameObject.Find("PlayerArmour"); if (playerArmour == null) { } else { playerArmour playerArmourScript = playerArmour.GetComponent <playerArmour>(); playerArmourScript.changeArmour(currentArmour, currentArmourIndex); //notify user that armour was taken notificationBox.GetComponentInChildren <Text>().text = "Your current armour is level " + (currentArmour.level + 1); break; } } } }
private void Awake() { DontDestroyOnLoad(transform.gameObject); if (playerArmourInstance == null) { playerArmourInstance = this; } else { Destroy(gameObject); } }
// Start is called before the first frame update void Start() { //show what current armour level is GameObject playerArmour = GameObject.Find("PlayerArmour"); if (playerArmour == null) { } else { playerArmour playerArmourScript = playerArmour.GetComponent <playerArmour>(); //display level is + 1 compared to level it is saved as notificationBox.GetComponentInChildren <Text>().text = "Your current armour is level " + (playerArmourScript.GetArmour().level + 1); } //get the data of what armour the person has ArmourData data = SaveSystem.loadArmour(); if (data != null) { armourList.playerArmour = data.playerArmour; } //disable icons as default for (int i = 0; i < armourIcons.Length; i++) { armourIcons[i].SetActive(false); } //enable icons for (int i = 0; i < armourList.playerArmour.Count; i++) { int armourNum = armourList.playerArmour[i].level; armourIcons[armourNum].SetActive(true); numberArmourAvailable[armourNum] = numberArmourAvailable[armourNum] + 1; armourIcons[armourNum].GetComponentInChildren <Text>().text = "Take Armour (Number Owned: " + numberArmourAvailable[armourNum] + ")"; } }