Forum rules - please read before posting.

How to check item being selected and clear all items (by script)

edited January 2015 in Technical Q&A
Through google,I find 
 GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeInventory> ().selecteditem
will detect which item is select now.But I found if I add a actionlist (named useitem)to each item in the 'use' place of (inventery manage tab)The select will not work any more.I think this because the system give all the work to the user and include select which item.
This problem cause that I must assign each item a different actionlist to tell the system which item is select now.I always work in script so I think this may cause much work and not good for code arrangement.So I wanner ask if there is a better way to detect which item is selected (I need this founcton because I made a new panel ui to 'zoom' each selected item) with one script or actionlist by sending params to know them.

The next problem is easy.I don't need system to save the items player carried,each time I reset the scene,I wanner clear the menu and all items.
I tried RuntimeInventory tInv =  GameObject.FindWithTag (Tags.persistentEngine).GetComponent <RuntimeInventory> ();
tInv.localItems.Clear ();
It did not sync the menu automatically so I must restart the game twice to show a clear menu.
Any way to deal with this.Thankyou very much.

Comments

  • edited January 2015
    First off, 1.41 provides a much easier way of referencing scripts: no more do you need to use GetComponent, you can just reference a static function.  RuntimeInventory, for example is now:

    AC.KickStarter.runtimeInventory

    Secondly, it's not completely clear what you're trying to do.  When asking technical questions (especially those related to scripts), please take extra care when explaining your problem.

    You don't need to assign an ActionList to each "Use" interaction - the lack of one will select the item automatically (unless you want to do more than just that).

    In any case, selectedItem should always return the selected item.  But to select an item through script, it's better to use the SelectItem or SelectItemByID functions.

    As for clearing your menus, you will have to call this function after clearing the inventory, to reset the inventory boxes:

    AC.PlayerMenus.ResetInventoryBoxes ();
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.