Skip to content

PrimeTween for basic 2D sprite animations? #72

Answered by KyryloKuzyk
wundev asked this question in FAQ
Discussion options

You must be logged in to vote

Hey!

Although there is no built-in support for this, it's absolutely possible to use PrimeTween for simple sprite animations. Here is a simple script:

using System;
using PrimeTween;
using UnityEngine;
using UnityEngine.Assertions;

[Serializable]
public class SpriteAnimation {
    [SerializeField] SpriteRenderer spriteRenderer;
    [SerializeField] Sprite[] sprites;
    [SerializeField] TweenSettings settings = new TweenSettings(1f, Ease.Linear, cycles: -1);
    int curIndex = -1;

    public Tween Play() {
        Assert.IsNotNull(spriteRenderer, nameof(spriteRenderer) + " reference is not populated in Inspector.");
        Assert.IsTrue(sprites != null && sprites.Length > 0, "Sprites a…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by KyryloKuzyk
Comment options

You must be logged in to vote
2 replies
@KyryloKuzyk
Comment options

@wundev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
FAQ
Labels
None yet
2 participants