So I am working on a game. In the game I plan to make a buy shop so that way you can buy weapons ,but here is the problem. I have two scripts. One is an inventory manager and the second handles the buy script.
I want to make individual weapons cost something else ,but I have no idea how to do that with both of these scripts.
If anyone has any idea on how to make individual costs for each weapons then your help would be nice. I’m a begginer in Unity so…
My inventory manager script:
public GameObject Player;
public GameObject[] weapons;
public bool[] weaponAvailable;
int CurrentWeapon;
// Use this for initialization
void Start () {
weaponAvailable = new bool[weapons.Length];
for (int i = 0; i < weapons.Length; i++) {
weaponAvailable = false;
}
CurrentWeapon = 0;
weaponAvailable [CurrentWeapon] = true;
deactivateWeapon ();
SetWeaponActive (CurrentWeapon);
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Submit")){
int i;
for (i = CurrentWeapon + 1; i < weapons.Length; i++) {
if (weaponAvailable == true) {
CurrentWeapon = i;
SetWeaponActive (CurrentWeapon);
return;
}
}
for (i = 0; i < CurrentWeapon; i++) {
if (weaponAvailable == true) {
CurrentWeapon = i;
SetWeaponActive (CurrentWeapon);
return;
}
}
}
}
public void SetWeaponActive(int whichweapon){
if (!weaponAvailable [whichweapon]) {
return;
}
deactivateWeapon ();
weapons [whichweapon].SetActive (true);
weapons [whichweapon].GetComponentInChildren<FireBullet> ().initiazeWeapon ();
}
void deactivateWeapon(){
for (int i = 0; i < weapons.Length; i++) {
weapons .SetActive (false);
}
}
public void ActivateWeapon(int WhichWeapon){
weaponAvailable [WhichWeapon] = true;
}
My buy script:
```csharp
*public GameObject UI;
public GameObject Player;
public GameObject GameOver;
public GameObject Pause;
public GameObject Gamemanager;
public int whichweapon;
public bool PlayerIsBuyingSomething = false;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.C)) {
toggle ();
}
}
public void toggle(){
if (GameOver.GetComponent<GameOver>().GameIsOver == true) {
return;
}
if (Gamemanager.GetComponent<Pause> ().GameIsPaused == true) {
return;
}
UI.SetActive (!UI.activeSelf);
if (UI.activeSelf) {
Time.timeScale = 0f;
Player.GetComponentInChildren<FireBullet> ().enabled = false;
PlayerIsBuyingSomething = true;
} else {
Time.timeScale = 1f;
Player.GetComponentInChildren<FireBullet> ().enabled = true;
PlayerIsBuyingSomething= false;
}
}
public void Buy(){
if (PlayerStats.HighScore >= UI.GetComponentInChildren<WeaponCost>().WeaponCostInt) {
if (Player.GetComponent<InventoryManager> ().weaponAvailable [whichweapon] == false) {
Player.GetComponent<InventoryManager> ().ActivateWeapon (whichweapon);
PlayerStats.HighScore -= UI.GetComponentInChildren<WeaponCost> ().WeaponCostInt;
} else {
Debug.Log ("You already have that weapon");
}
} else {
Debug.Log ("Not enough money to buy this weapon!");
}
}*</em></em></em>
```