Making a function only happen once in the entire game.

Hello! I figure the best way to do this is simply to define things and save it in a file if it is enabled or not, but I was wondering if there is a better way to do things?

Heres my scenario:

I have an object which gives the player an Item (Let us call it ItemA) and I want it to only give it once, easy enough, only trigger it once then disable the script component that gave the item.

But when restarting the game, the trigger/object/script would obviously be enabled again.

I was just wondering, is there a good way to keep track of this or should I simply just put the “use” information in a file and call it to check whether to disable or enable an object?

You can use PlayerPrefs to save data.

PlayerPrefs.SetString("itemGiven", "true");

you can then use PlayerPrefs.GetString("itemGiven") == "true" to check if it has been set already.