Unity-AnimationUI icon indicating copy to clipboard operation
Unity-AnimationUI copied to clipboard

Object motion callbacks added

Open QQ1273459693 opened this issue 1 year ago • 1 comments

It would be perfect if you could implement a callback after each movement, e.g., after object A moves to position B, I'll move A to position C again, and then I'll call the callback after each movement.

QQ1273459693 avatar Mar 28 '24 07:03 QQ1273459693

Try this Callback in AnimationUI

Bassically its:

  1. Move transform A From position A to potition B for x seconds
  2. Wait x seconds
  3. Call unityevent
  4. Move transform A From position B to potition C y seconds
  5. Wait y seconds
  6. Call unityevent

Instead of callback in each sequence, you can add an event that calls the function you want to call.

Or you can also do it with code like this if you don't want to add it in the inspector. (I didnt make a clear documentation for it tho):

using UnityEngine;

public class CallbackTest : MonoBehaviour
{
    // Assign the AnimationUI component in the inspector
    [SerializeField] AnimationUI animationUI;

    void Start()
    {
        animationUI.AnimationSequence[2].Event.AddListener(AfterAMoveToB);
        animationUI.AnimationSequence[5].Event.AddListener(AfterAMoveToC);
    }

    void AfterAMoveToB()
    {
        Debug.Log("Callback After A move to B");
    }

    void AfterAMoveToC()
    {
        Debug.Log("Callback After A move to C");
    }
}

Another alternative is to add multiple AnimationUI component. Then look at the Readme.md and use the AddFunctionAtEnd to each animation. Make sure the second one has wait sequence.

DhafinFawwaz avatar Mar 30 '24 06:03 DhafinFawwaz