void UpgradeWeapon() { money -= nextUpgradeCost(); cannonLevel++; CannonProperties newCannonProperties = Cannons.getCannonProperties(cannonLevel); if (cannonObj.GetComponent <Cannon>().GetCannonProperties().cannonType != newCannonProperties.cannonType) { InitCannon(); } else { cannonObj.GetComponent <Cannon>().SetCannonProperties(newCannonProperties); } switch (newCannonProperties.cannonType) { case 1: upgradeButton.GetComponent <Image>().sprite = cannonSprites[0]; break; case 2: upgradeButton.GetComponent <Image>().sprite = cannonSprites[1]; break; case 3: upgradeButton.GetComponent <Image>().sprite = cannonSprites[2]; break; } }
void InitCannon() { CannonProperties cannonProperties = Cannons.getCannonProperties(cannonLevel); if (cannonObj != null) { GameObject newcannonObj = (GameObject)GameObject.Instantiate(Resources.Load(string.Format("Prefabs/{0}", Cannons.getPrefabName(cannonProperties.cannonType)))); newcannonObj.GetComponent <Cannon>().SetCannonProperties(cannonProperties); initiateStylishCannonSwitch(cannonObj.GetComponent <Cannon>().transform, newcannonObj.transform); cannonObj.GetComponent <Cannon>().Kill(); cannonObj = newcannonObj; } else { cannonObj = (GameObject)GameObject.Instantiate(Resources.Load(string.Format("Prefabs/{0}", Cannons.getPrefabName(cannonProperties.cannonType)))); cannonObj.GetComponent <Cannon>().SetCannonProperties(cannonProperties); } }