- Home /
Skin issues with Spine
I am using Spine for my 2D art. I have a problem though. I need to toggle between 2 skins for one of my enemy sprites like so:
I wrote the code that toggles said skin,
public class EnemyBehavior : MonoBehaviour {
public GameObject enemy;
//Reactions between rock enemy and player
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("enters");
if (other.gameObject.tag == Constants.Player)
{
enemy.GetComponent<SkeletonAnimator>().initialSkinName = "Alert";
}
}
void OnCollisionExit2D(Collision2D other)
{
if (other.gameObject.tag == Constants.Player)
{
enemy.GetComponent<SkeletonAnimator>().initialSkinName = "NoAlert";
}
}
}
It even shows in the inspector that the character's Initial Skin name changes but not the skin itself therefore the character is stuck on the first skin I assign it.
What I found out is that when I click on the Reload button at the upper right of the Skeleton Animator script the skin changes!
My question then becomes: is it possible to call the Reload button through code? And if so, how do I access it? Many thanks in advance!
Answer by manuelmangual · Sep 01, 2016 at 11:24 PM
So I found the solution! My problem was that I was setting the name text rather than call the actual skin name. For that all I had to do was to call this function in script:
enemy.GetComponent<SkeletonAnimator>().skeleton.SetSkin(Constant.SkinName);
Your answer
Follow this Question
Related Questions
Enemy to follow player after animation completes 1 Answer
My animations are messed up 1 Answer