Forum rules - please read before posting.

Left-click to Use, Hover to Examine

2»

Comments

  • @ChrisIceBox Hm seems like the menu shows up on the hotspot when an inventory item is selected, and it looks like the description is not being updated since the examine action is not being run.

    Is there anyway I can preserve the inventory cursor and have the examine interaction run in the background?

    Thanks!

    @jussik yay!! That is awesome to hear! :)

  • A Menu set to appear "On Hotspot" will display when over Hotspots and Inventory items - regardless of its content.

    You could switch to Manual and use scripting to manually turn it on when over a Hotspot - or use the Events Editor to lock the Menu when over the Inventory, and unlock it when selecting a Hotspot. This'd be done with the Menu/Hover and Hotspot: Select events.

    To have the examine Interaction run in the background, alter its When running field in the ActionList's properties box.

  • Ah, the issue is that when I select an inventory item, the cursor is that inventory item, but when I drag it over to a hotspot, the description doesn't seem to be updated.

  • edited January 8

    I think I found a bit of a workaround --

    The only remaining question I have is, Is it possible to make my player face an object through scripting? (not an actionlist, but somehow make the player face a gameobject I define as a public parameter in the auto-examine script and then run that action through my code?

    using UnityEngine;
    using AC;
    
    public class AutoExamineHotspot : MonoBehaviour
    {
    
        // the description of the hotspot to manually set
        // when an inventory item is selected.
        private string description;
    
        private void OnEnable () { EventManager.OnHotspotSelect += OnHotspotSelect; }
        private void OnDisable () { EventManager.OnHotspotSelect -= OnHotspotSelect; }
    
        private void OnHotspotSelect (Hotspot hotspot)
        {
            // auto-run examine interaction if no inventory item selected
            if (KickStarter.runtimeInventory.SelectedItem == null)
            {
                hotspot.RunExamineInteraction ();
            } else
            {
                description = "Combine " +
                    KickStarter.runtimeInventory.SelectedItem.label +
                    " with " +
                    hotspot.GetName(0);
    
                // set description to combine interaction
                GlobalVariables.GetVariable("HotspotDescription").SetStringValue(description);
            }
        }
    
    }
    
  • If you want the game to wait while they turn, you're best off using an ActionList (which can also be entirely scripted - see the Manual's "Generating ActionLists through script" chapter), but simply pointing a character in a given direction is just a case of calling their SetLookDirection function.

    If you have a Marker variable that points in the intended direction, you can refer to its ForwardDirection property, e.g.:

    Char myCharacter;
    Marker myMarker;
    myCharacter.SetLookDirection (myMarker.ForwardDirection);
    
  • Ah thank you so much!

    I looked at that section in the manual as well -- it seems like the actionlist is null.

    I'm adding the component in the onstart function, and I made sure to drag and drop the instance of my player into the component script field. Is there something else I might be missing?

    This is my code:
    `using UnityEngine;
    using AC;
    using UnityEngine.TextCore.Text;
    using System.Collections.Generic;

    public class AutoExamineHotspot : MonoBehaviour
    {

    // the description of the hotspot to manually set
    // when an inventory item is selected.
    private string description;
    ActionList actionList;
    public Char myCharacter;
    
    private void onStart()
    {
        actionList = gameObject.AddComponent<ActionList>();
        actionList.actions = new List<Action> {
        ActionCharFace.CreateNew_BodyFace(myCharacter, this.gameObject)
        };
    }
    
    private void OnEnable() { EventManager.OnHotspotSelect += OnHotspotSelect; }
    private void OnDisable() { EventManager.OnHotspotSelect -= OnHotspotSelect; }
    
    private void OnHotspotSelect(Hotspot hotspot)
    {
        // auto-run examine interaction if no inventory item selected
        if (KickStarter.runtimeInventory.SelectedItem == null)
        {
            hotspot.RunExamineInteraction();
        }
        else
        {
            description = "Combine " +
                KickStarter.runtimeInventory.SelectedItem.label +
                " with " +
                hotspot.GetName(0);
    
            // set description to combine interaction
            GlobalVariables.GetVariable("HotspotDescription").SetStringValue(description);
    
            Debug.Log("actionList is ", actionList);
            actionList.Interact();
    
    
        }
    }
    

    }`

  • Also DM'd you a link to my repo as a collaborator just in case that would help @ChrisIceBox (for a different issue, but thought of asking regarding this one too!)

    The object in question is the ice pick in the forest2 scene. It's at the very left of the scene.

    It's my most recent commit with the message "COMMIT: WILL REVERT IF NULL ISSUE NOT FIXED"

  • Looks like a typo - replace onStart with Start.

  • Ah that was it! Completely forgot Unity's Start function name there haha -- thank you!

  • edited February 1

    @ChrisIceBox Actually sorry to circle back on this, but is it possible to have this menu pop up on inventory items, on hover, in the inventory box?

    It looks like the menu does pop up, but I have to right-click the item so that the description is correctly assigned (I assigned an actionlist to the examine interaction for one of my inventory items just to test out).

    From the most recent script posted above, I was hoping to make this work, but I don't think I can assign the script as a component to the inventory item.

  • Quick note on the above script: if you're attaching multiple instances of it in the scene, you'll need to have it check for the currently-selected Hotspot - the event is run for each instance, so otherwise you'll get each running at the same time:

    private void OnHotspotSelect(Hotspot hotspot)
    {
        // auto-run examine interaction if no inventory item selected
        if (hotspot.gameObject != gameObject) return;
    

    For inventory items, a single instance of a new script will need to be placed in the scene - this time hooking into the OnInventoryHover event.

  • @ChrisIceBox Ah yes! Sorry I realized the script above was outdated -- I added that part in my code, thank you for pointing it out!

    Sounds great! I shall go ahead and take a look at it -- thank you so much! :) I'm thinking this would need to be done in every scene, the script will need to be placed on an empty gameobject?

  • It'll need to be in each scene - but you can use the Events Editor to automate this.

    Use this window to create a new Scene: Change: After event, and then have this run an Object: Add or remove Action that spawns the script (attached to a prefab) to the scene.

  • Awesome, thank you so much!

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.