Forum rules - please read before posting.

Default animation for every interaction

I've decided that almost every interaction of my player should be preceded by a simple "doing" animation (like he's pressing an invisible button).

I've added a flag for skipping "doing" animation to the "Button.cs" file (so I can turn it off for some cases):

public bool skipAdemDo = false;

...and added an ActionListAsset variable as a private class member of PlayerInteraction at the "PlayerInteraction.cs":

ActionListAsset _alAdemDo = null;

And the last addition goes to the UseObject method of the same file, after the code

if (button.faceAfter)
    {
        lookVector = _hotspot.walkToMarker.ForwardDirection;
        lookVector.y = 0;

        KickStarter.player.EndPath ();
        KickStarter.player.SetLookDirection (lookVector, false);

        while (KickStarter.player.IsTurning ())
        {
            if (doSnap)
            {
                KickStarter.player.SetLookDirection (lookVector, true);
                break;
            }

            yield return new WaitForEndOfFrame ();          
        }

...I've added this fragment:

if (!button.skipAdemDo && KickStarter.player.name == "AdemPlayer")
{
    if (_alAdemDo == null)
        _alAdemDo = Resources.Load("alAdemDo") as ActionListAsset;

    if (_alAdemDo != null)
    {
        _alAdemDo.Interact();

        while (_alAdemDo.actions[0].isRunning)
            yield return new WaitForEndOfFrame();
    }
}

"alAdemDo" is a simple one-action interaction lying in the Resources folder which just plays the "do" animation.

So now, when the default player named "AdemPlayer" walks to the marker, he plays "do" animation and only after that the certain interaction is being run.

Maybe someone will find it useful =). And if there're more correct ways to do it, I'll be happy to hear =).

Comments

  • If you hook a custom script into the OnHotspotInteract event, it should be possible without the need to modify the source. Since this event is called at the time the Player clicks on the Hotspot, you can modify the Hotspot before the Interaction ActionList is actually run.

    e.g.:

    using UnityEngine;
    using AC;
    
    public class PreInteractionAnim : MonoBehaviour
    {
    
        private AC.Button lastClickedButton;
        private static ActionListAsset alAdemDo;
    
        private void OnEnable ()
        {
            EventManager.OnHotspotInteract += OnHotspotInteract;
            EventManager.OnEndActionList += OnEndActionList;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotInteract -= OnHotspotInteract;
            EventManager.OnEndActionList -= OnEndActionList;
        }
    
        private void OnHotspotInteract (Hotspot hotspot, AC.Button button)
        {
            if (hotspot == GetComponent <Hotspot>() && button != null)
            {
                hotspot.interactionSource = InteractionSource.AssetFile;
                lastClickedButton = button;
    
                if (alAdemDo == null)
                {
                    alAdemDo = Resources.Load ("alAdemDo") as ActionListAsset;
                }
    
                button.assetFile = alAdemDo;
            }
        }
    
        private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
        {
            if (actionListAsset == alAdemDo && lastClickedButton != null)
            {
                lastClickedButton.interaction.Interact ();
                lastClickedButton = null;
            }
        }
    
    }
    
  • It works great, thanks a lot, Chris!

  • I guess we have to save the hotspot and its interaction source in the OnHotspotInteract method:

    _interactionSource = hotspot.interactionSource;
    _hotspot = hotspot;
    

    And then restore the interaction source for the hotspot in the OnEndActionList method:

    _hotspot.interactionSource = _interactionSource;

    Otherwise, we'll lost all interactions of the hotspot if previous interactionSource value was not AssetFile, but InScene, for example.

  • The data is still retained, and since the script hard-sets the interaction source to Asset File, repeated runs of the same interaction should still work.

    You may well want to backup/restore the source value, though, depending on your needs.

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.