So, I currently have my inventory set to drag item, but I would like to try out a different way:
Once the item is selected, the inventory closes, the item stays selected rather than drag, and the item stays selected until right click or the item is used correctly (ie not an unhandled event)
Happy for the cursor to close with drag once the cursor is out of the inventory area
My inventory is animated using ON/OFF etc
Thanks
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You can disable drag-and-drop mode from the Settings Manager.
If Interaction method is set to Context Sensitive, or Inventory interactions is set to Single, then selecting an item with not "Use" interaction defined will cause it to become selected. Further options in the Settings Manager allow you to prevent it from becoming de-selected when left-clicking.
A script that hooks into the OnInventorySelect event can be used to turn off the Inventory menu when an item is selected:
ok thanks, i will give this a try, can i ask how i would add a line of code to animate a ui prefab menu game object from here also?
This is the object and animation:
https://www.dropbox.com/s/go49w4762zq4bvr/animate from script.png?dl=0
If you define a Trigger parameter in your Animator that causes the animation to play, you can invoke it through script with:
could i combine the two script codes with this (this closes the inventory menu when player walks)? And how would be best to add it in?
I don't think it is currently having effect on the briefcase, is that the right line for the script when it is set in the prefab UI as in screenshot? Also screenshot of trigger set up:
https://www.dropbox.com/sh/px8takv5aanw24x/AADN49Qwbt9JlUZcSP9yxxJPa?dl=0
Replace "MyTrigger" with the name of the actual parameter you want to trigger - in this case, "Close".
Is the Briefcase object enabled in the Hierarchy at the time?
Uncheck "Has Exit Time" in the transition, too.
https://www.dropbox.com/sh/1bd2ojqd4kc0j2r/AAA20C7qnC3d6QIVfvfs8ZDra?dl=0
The Animator you're showing is for ToyChest, but the script you've posted is for Briefcase, which is disabled at the time of the video.
GameObject.Find ("Briefcase").GetComponent<Animator>().SetTrigger ("Close");
GameObject.Find ("ToyChest").GetComponent<Animator>().SetTrigger ("Close");
But it does still not close on player walk
I have sorted this now thanks!
How would I used the script above in scene?
The script above causes the object it's attached to to survive scene changes, making it scene-independent.
If you wanted it to work in a single scene, remove its Awake function.
ok thanks! How would i change this script to deselect the item once the player moves?
Follow up, I've realised that the inventory closing once an item is selected does not help with combining objects, as the player cannot see any other items to combine with, so instead, how do I have it that the inventory bar closes once the cursor is out of range of the inventory bar area? Thanks
If your Menu's "Appear type" is set to "Mouse Over", it will turn on/off when the mouse moves over/away from it.
Othewise, you can read the mouse position directly and turn it off/lock it based on its value:
Have tried this script ands it is not showing my inventory menu at all? see video:
https://www.dropbox.com/s/obq1m06docxv7ix/MouseOver.mov?dl=0
It's a sample script - you will need to adapt it to suit your needs.
ah ok, so play with height number?