- Home /
How to acces Scribtable object data from button?
So the problem is that i have buttons acting as upgrades, when clicked player buys the upgrade. I also have the different upgrades as ScriptableObjects so i can quickly create new ones. Now i need a script that recognizes which button is pressed and pulls the data stored in the scriptableObejct assigned to that button. So basically if i have health =85, and i buy more healt, button is pressed, amount of health stored in the object gets added to health that had already. This is what i have now:
public class UpgradeManagerScript : MonoBehaviour {
public Button button;
public void OnClicked(Button button)
{
print(button.name);
}
i get the name of the button but cant access the values stored in the scriptableObject.
Answer by Commoble · Feb 07, 2018 at 06:17 PM
Declare a public NameOfTheScriptableObjectClass objectField;
field in your UpgradeManagerScript class; this will create an inspector field in your script that you can drag an instance of your ScriptableObject to, which you can then reference as needed.
Will this work only if button is pressed and the information from that spesific button is accessed? Like button.upgrade.health for example?
What you do with the button is up to you. The answer I gave is how to give your script a reference to a scriptable object instance, which you can then use however you need.
Okay, so this works, but i get an error "ArgumentException: failed to convert parameters" what could this be about? parameter i am trying to access is int.
Your answer

Follow this Question
Related Questions
[SOLVE] OnMouseEnter not working on UI elements 2 Answers
changing script from key based function to GUI button for dice roll game 1 Answer
Custom Editor Button Style like the one in the Hierarchy 0 Answers
How to change RawImage texture to another one when i press a buton for it 0 Answers
How can i make downloadable content? 1 Answer