Hi, I'm making a 2D game with the direct movement method using a keyboard.
I have an inventory with 5 slots. I set 2 buttons to offset it 1 slot at a time. Let's say I have 10 items. When the first time I open the inventory, it'll show the first 5 items. If I offset it forward 3 times, for example, it'll now show the items #4-8. When I turn the inventory off and then turn it on again, it's still offset and shows the items #4-8. Is it possible to make it show the first 5 items like the first time I opened it?
Thanks a lot!
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Yes - though you'll need a custom script to do so, as it involves calling the InventoryBox element's ResetOffset function as the Menu turns on.
This should do it:
Hi, I can't figure out how to make it work. Could you point out where I'm doing wrong?
I added the script to a gameobject prefab
https://drive.google.com/file/d/1m4cKqjN--e4ZKmN6OLj70bCNvLUc6-XX/view?usp=sharing
I used Object: Send message in the Actionlist when turn on the Inventory to call the function. I tried to use it in other places but it didn't work either.
https://drive.google.com/file/d/1mdbFxhwSDK_FyxOcaiiuJyPVr_xo1mtc/view?usp=sharing
Here is my Inventory setup.
https://drive.google.com/file/d/1mDXmCHUzQDNf7QLiKvlBRbYWvx7Kin35/view?usp=sharing
I also changed the menu name in the script to match the menu.
Here is the video test
https://drive.google.com/file/d/1mjGRJKaT1vb7W3LgAXtulJS3qEKABGrQ/view?usp=sharing
The script is self-contained: it hooks into the OnMenuTurnOn custom event, which kicks in automatically. You don't need to use Object: Send message.
The component in your screenshot isn't enabled, however - make sure it's enabled and present in the scene, and it should work.
I put the script in the Persistent Engine prefab and it works. Thanks a lot for the help, Chris!