Hi friends,
I've got some questions for you, for more experienced of you using Spine & Unity:
- If I got a lot of Spine animation in one scene let's say hundreds (150-300), what is the best way to achieve best performance:
a) using sqrMagnitude distance between player & animation for triggering (enabling) SkeletonAnimation:
My example code:
SkeletonAnimation ska;
void Awake()
{
ska = GetComponent<SkeletonAnimation>();
}
void LateUpdate()
{
AnimateTest();
}
private void AnimateTest()
{
//CALCULATE THE DISTANCE FROM PLAYER TO THE ANIMATION
float tempDist = (player.transform.position - transform.position).sqrMagnitude;
distance = tempDist;
//ANIMATE
if (player != null)
{
if (distance < _animateDistance )
{
if (!ska.enabled)
{
ska.enabled = true;
}
ska.loop = true;
ska.AnimationName = animAttack;
ska.timeScale = 0.7f;
Debug.DrawLine(transform.position, player.transform.position, Color.red);
Debug.Log("THE DISTANCE BETWEEN PLAYER & ANIM_OBJ: " + distance);
}
}
if (distance <= 40)
{
transform.rotation = Quaternion.Euler(0f, -180f, 0f);
}
else if (distance > _animateDistance )
{
ska.enabled = false;
ska.loop = false;
ska.timeScale = 0f;
Debug.DrawLine(transform.position, player.transform.position, Color.green);
Debug.Log("THE DISTANCE BETWEEN PLAYER & ANIM_OBJ: " + distance);
}
}
b) activate the SkeletonAnimation using colliders (2D in my case) e.g:
void OnTriggerEnter2D(Collider2D o)
{
if(o.gameObject.tag == "Player")
{
ska.enabled = true;
}
}
*P.S: I'm developing for mobile devices !
Any advice & feedback will be much appreciated, thanks in advance ! :handshake: :beer: