Forum rules - please read before posting.

Animating an inventory item in the inventory (hover)

Hi,

Are you able to help me get started in animating an inventory object in the inventory when hovered over? and when selected? Is there a tutorial available?

Thank you!

Comments

  • The ability to override an item's texture through script will be introduced in the next update - please wait until then.

  • Awesome! ok thanks

  • This still coming soon Chris?

  • It was included in v1.76.1.

    With the update, you can override an item's texture with the InvInstance class's Tex property.

    Here's an example script that should let you animate a specific item when it's hovered over, by cycling through an array of textures in an Update loop:

    using UnityEngine;
    using AC;
    
    public class AnimateItemOnHover : MonoBehaviour
    {
    
        public Texture[] animFrames;
        public float frameDelay = 0.2f;
        public int itemID;
        private InvInstance lastHoverInstance;
        private float timer;
        private int frameIndex;
    
        private void Update ()
        {
            InvInstance invInstance = KickStarter.runtimeInventory.HoverInstance;
            if (!InvInstance.IsValid (invInstance) || invInstance.ItemID != itemID)
            {
                if (InvInstance.IsValid (lastHoverInstance))
                {
                    lastHoverInstance.Tex = null;
                    lastHoverInstance = null;
                }   
                return;
            }
    
            lastHoverInstance = invInstance;
            timer += Time.deltaTime;
            if (timer >= frameDelay)
            {
                frameIndex ++;
                if (frameIndex >= animFrames.Length) frameIndex = 0;
                lastHoverInstance.Tex = animFrames[frameIndex];
            }
        }
    
    }
    
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.