Forum rules - please read before posting.

Animating inventory icon

I wrote a little script to animate regular inventory icons exactly like the cursor icon:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AC;

public class AnimatedIcon : MonoBehaviour
{

    private Texture2D IconMain;
    private Texture2D IconAnimated;

    void Update()
    {

        IconAnimated = AC.KickStarter.runtimeInventory.GetItem(1).cursorIcon.GetAnimatedTexture(true);

        if (IconMain != IconAnimated)
        {            
            AC.KickStarter.runtimeInventory.GetItem(1).tex = IconAnimated;
            IconMain = IconAnimated;
            Debug.Log("animating!");

        }

    }
}

It works, but the debug log appears to be running every frame instead of only when the cursor icon actually changes (animation speed is set to 1). Any idea why? It doesn't seem to be causing any performance issues, but I figure I'd ask.

Comments

  • You're running the code in Update, so it will be set every frame - even if the texture itself isn't changing.

    As an aside: as of v1.76.1 it's now possible to override item textures on a per-instance basis, as opposed to the original item asset you're affecting now.

    If you replace:

    AC.KickStarter.runtimeInventory.GetItem(1).tex = IconAnimated;
    

    with:

    AC.KickStarter.runtimeInventory.PlayerInvCollection.GetFirstInstance (1).Tex = IconAnimated;
    

    Then you'll affect the first-found instance of the item in the Inventory, as opposed to the original asset.

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.