Forum rules - please read before posting.

ActionList: Object: Animate via Script

I'd like to perform this animation through a script but I do not know how:
https://imgur.com/a/8hsiiWL

I do not find any information on how to play a legacy animation using PlayCustom in the scripting guide. Any help is appreciated :smile:

Comments

  • In AC, "legacy" refers to Unity's old Animation component - so for info on manipulating it through script you'll want to refer to Unity's Script Reference pages here:

    https://docs.unity3d.com/ScriptReference/Animation.html

    However, AC does provides a helper function, PlayAnimClip, that can be used to play legacy animation clips on an object. This is what the Action calls when the Play Custom method is used:

    AC.AdvGame.PlayAnimClip (myAnimation, layer, myAnimationClip);
    
  • Thanks, because the myAnimation and myAnimationClip were more confusing to me than using some code I found and modifying it to suit my needs this is what I came up with just for reference if someone else wants to animate via C# as well:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using AC;
    
    public class ObjectPickup : MonoBehaviour
    {
        public GameObject obj;
        public Animation anim;
    
        private bool pickingUp = false;
    
        void Start()
        {
            obj = GameObject.FindWithTag("Collectable"); // or however you want to get the object
            anim = obj.GetComponent<Animation>();
        }
    
        void pickup()
        {
            if (obj != null)
            {
                anim.Play("MyAnimation"); // whatever your animation is called
                pickingUp = true;
            }
        }
    
        void Update()
        {
            if (pickingUp && !anim.isPlaying)
            {
                // No animations are playing
                pickingUp = false;
    
                // Teleport to global hidden position
                obj.transform.position = new Vector3(0, 0, 0);
            }
        }
    }
    

    This is actually for picking up an item and then teleporting it to another position to hide it. Teleporting should only happen after the animation has finished.
    Probably some better way to do it but sufficient for me ;)

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.