FANDOM


This script is used to automate the flipping of characters animated with the Sprites Unity Complex engine when facing a particular direction.

This is similar to the "Frame flipping" option when using the Sprites Unity engine, where left-facing animations can be flipped when facing right (and vice-versa).

To use:
1) Setup your character using the Sprites Unity Complex engine as normal
2) Update your Animator so that he plays the left-facing equivalent of any right-facing animation (or vice-versa) when appropriate.
3) Place the code below in a C# script named SUC_FrameFlip
4) Place the script on the character and assign the fields - setting the charater's Sprite child as the Transform To Flip.

NOTE: This script works by inverted the X-scale of the Transform whenever the facing-angle falls between 0 and 180 degrees (or 180 and 360, depending on the frameFlipping value).  This will cause up and down animations to be flipped as well.  To prevent this, modify these values in the code to suit the needs of your own character.Edit
using UnityEngine;
using System.Collections;
using AC;

public class SUC_FrameFlip : MonoBehaviour
{

    [SerializeField] private AC.Char character;
    [SerializeField] private Transform transformToFlip;
    [SerializeField] private AC_2DFrameFlipping frameFlipping;

    private void Update ()
    {
        if (frameFlipping == AC_2DFrameFlipping.None || character == null || transformToFlip == null)
        {
            return;
        }

        bool doFlip = false;
        float spriteAngle = character.GetSpriteAngle ();

        if (frameFlipping == AC_2DFrameFlipping.LeftMirrorsRight)
        {
            if (spriteAngle >= 0f && spriteAngle < 180f)
            {
                doFlip = true;
            }
        }
        else if (frameFlipping == AC_2DFrameFlipping.RightMirrorsLeft)
        {
            if (spriteAngle > 180f && spriteAngle <= 360f)
            {
                doFlip = true;
            }
        }

        if ((doFlip && transformToFlip.localScale.x > 0f) || (!doFlip && transformToFlip.localScale.x < 0f))
        {
            transformToFlip.localScale = new Vector3 (-transformToFlip.localScale.x, transformToFlip.localScale.y, transformToFlip.localScale.z);
        }
    }
    
}

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.