Hello, so I am trying to make a script that adds and subtracts a certain amount to different resources, this works fine, however I seem to be having an issue with updating the amount that is added/subtracted from each resource. The actually change of the int seems to work fine, but the “public void Converter()” that I use does not change, keeping only the initial int as its int. Is there I way I can make this function update, I need it to be public to access it from a button. Below is my script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Resource_ConverterClick : MonoBehaviour {
private Resource_Inventory myResource_Inventory;
public Button generate;
public int AddingResourcesFuel = 5;
public int AddingResourcesElectric = 20;
void Start()
{
myResource_Inventory = GameObject.Find("ResourcesHUD").GetComponent<Resource_Inventory>();
}
void Update()
{
if (myResource_Inventory.currentResourceFuel <= 0)
{
myResource_Inventory.currentResourceFuel = 0;
generate.interactable = false;
}
if (myResource_Inventory.currentResourceFuel > 0)
{
generate.interactable = true;
}
}
public void ConverterRate5_20()
{
AddingResourcesFuel = 5;
AddingResourcesElectric = 20;
}
public void ConverterRate15_60()
{
AddingResourcesFuel = 15;
AddingResourcesElectric = 60;
}
public void Converter()
{
myResource_Inventory.AddResourcesFuel(-AddingResourcesFuel);
myResource_Inventory.AddResourcesElectric(AddingResourcesElectric);
}
}
For example, my “-AddingResourcesFuel” int keeps with the int 5 even after I make it change to 15, does anyone know how to solve this?