Unlockable Item - flexible component for things that should be unlocked. It saves item state (locked/unlocked).
Use Placement - allows to use placement as an unlock trigger.
Placement - component link.
Hide Placement After Unlock - placement will be hided after unlock.
Use Button Buy - allows to use Button Buy as an unlock trigger.
Button Buy - component link.
Button Text After Unlock - text which will be shown after unlock.
Use Price Text - allows to use price text (it can be necessary if you use placement and need to show the price)
Text - text mesh pro link.
Price Text After Unlock - text which will be shown after unlock.
Id - it can be a random number, but all items must have a different id.
Is Unlocked By Default - item first launch state which will be saved.
Price - item price.
Payment Resource - resource to which the purchase will be paid.
On Unlock Item() - this event invokes on unlock.
UnlockableItemData.cs - a script that contains data about an item state.
[Serializable]
public class UnlockableItemData
{
public int Id;
public bool IsUnlocked;
}
QUESTIONS:
How to use the component?
Add the component to any object you want and set the settings: set id, default state and price.
After it choose the way you want to use as a trigger to unlock: you can use placement or button buy if you use any ui panel. Also if you use placement, you can turn on Use Price Text, use Placement with Text prefab and drag and drop text there.
After that, the component is fully configured. Now you just need to realize for yourself what should happen if the component is unlocked. You can create a script, subscribe to events and continue to do what you want.
2. How to subscribe event?
[SerializeField] private UnlockableItem _unlockableItem;
private void Start()
{
_unlockableItem.OnUnlockItem.AddListener(OnUnlock);
}
private void OnUnlock()
{
Debug.Log("Item unlocked!");
}