I have blink, idle, walk, and back animations all in the same file and tried mixing blink with idle and walk. However, the back animation flickers when I do this. When I call the back animation using Adventure Creator's Action, the Mesh Renderer’s materials have no elements, except when blinking, which only shows the closed eyelid element.
If I don't use my AnimationMixingSpine2D script, the back animation works fine. I'm a novice coder, I think the issue lies in the script.
I also found the SpineBlinkPlayer script from the Runtime Examples, but I'm unsure which Scene/Project it belongs to. If the SpineBlinkPlayer script is suitable, could you point me to the correct Scene/Project? Thank you.
`
using UnityEngine;
using Spine.Unity;
using System.Collections;
public class AnimationMixingSpine2D : MonoBehaviour
{
public SkeletonAnimation skeletonAnimation;
// Public animation names
public string idleAnimation = "idle";
public string walkAnimation = "walk";
public string runAnimation = "run";
public string talkAnimation = "talk";
public string blinkAnimation = "blink";
// Public variables to control animation speeds
public float blinkSpeed = 1.0f;
public float talkSpeed = 1.0f;
// Public variables to control blink frequency
public float minBlinkDelay = 2f;
public float maxBlinkDelay = 5f;
private Coroutine blinkCoroutine;
private Coroutine talkCoroutine;
void Start()
{
// Ensure SkeletonAnimation is assigned
if (skeletonAnimation == null)
skeletonAnimation = GetComponent<SkeletonAnimation>();
// Play idle animation on track 0 as default
SetBaseAnimation(idleAnimation);
// Start the blinking and talking animations
StartBlinking();
StartTalking();
}
void StartBlinking()
{
if (blinkCoroutine != null)
{
StopCoroutine(blinkCoroutine);
}
blinkCoroutine = StartCoroutine(BlinkingCoroutine());
}
void StartTalking()
{
if (talkCoroutine != null)
{
StopCoroutine(talkCoroutine);
}
talkCoroutine = StartCoroutine(TalkingCoroutine());
}
IEnumerator BlinkingCoroutine()
{
while (true)
{
float delay = UnityEngine.Random.Range(minBlinkDelay, maxBlinkDelay);
yield return new WaitForSeconds(delay);
var trackEntry = skeletonAnimation.AnimationState.SetAnimation(1, blinkAnimation, false);
trackEntry.TimeScale = blinkSpeed;
trackEntry.MixBlend = MixBlend.Add; // Ensure blending
trackEntry.Complete += (entry) =>
{
Debug.Log("Blink animation complete.");
};
}
}
IEnumerator TalkingCoroutine()
{
while (true)
{
float delay = UnityEngine.Random.Range(0.1f, 0.5f);
yield return new WaitForSeconds(delay);
var trackEntry = skeletonAnimation.AnimationState.SetAnimation(2, talkAnimation, false);
trackEntry.TimeScale = talkSpeed;
trackEntry.MixBlend = MixBlend.Add; // Ensure blending
trackEntry.Complete += (entry) =>
{
Debug.Log("Talk animation complete.");
};
}
}
// Public method to change the base animation (idle, walk, run, or talk)
public void SetBaseAnimation(string animationName)
{
skeletonAnimation.AnimationState.SetAnimation(0, animationName, true);
}
public void SetIdleAnimation()
{
SetBaseAnimation(idleAnimation);
}
public void SetWalkAnimation()
{
SetBaseAnimation(walkAnimation);
}
public void SetRunAnimation()
{
SetBaseAnimation(runAnimation);
}
public void SetTalkAnimation()
{
SetBaseAnimation(talkAnimation);
}
public void StopWalking()
{
SetIdleAnimation();
}
}
`