Cant access variables outside of On Click() function

I have a problem that i cant access the objectvariables outside this onClick function. I get the error: NullReferenceException: Object reference not set to an instance of an object. If i try to access these objectvariables inside the update function in the same class, its works fine.

In the objectvariables i set value = 20. As you can see in the code, inside the craftbuilding() function i set the value to 23. But this doesnt update the objectvariable. This also means that i get errors for buildingSelected and itemsInInventory since i cant access them inside this function.

Any help would be appreciated!

169346-pic1.jpg

show full code @Leonardot
I think that the function is not being called you should not put the script in the button instead you should put the script on an object and put the object in the button if it helps, please like