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: Code (CSharp): 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?
Maybe try... Code (CSharp): public void ConverterRates() { if (AddingResourcesFuel == 15 && AddingResourcesElectric == 60) { AddingResourcesFuel = 5; AddingResourcesElectric = 20; } else { if (AddingResourcesFuel == 5 && AddingResourcesElectric == 20 { { AddingResourcesFuel = 15; AddingResourcesElectric = 60; } } } }
I've tried what you gave me but it doesn't seem to affect the outcome, the public int during the game still changes but the converter() still keeps the original int, is there maybe someway of updating the int for the resources?
@DeanWebb the code you've pasted in the OP works fine here... is there anything else updating the values that might be interfering?
That's odd, there isn't anything else that I can think of that alters it, I'm currently updating unity though, thinking it may be an something wrong with the version I had. I will get back to you when its finished updating. Update: Updated unity and now seems to work fine, not sure what the issue was, will keep the script up to help anyone else though.