Hello Guest

Author Topic: Animating multiple sprites with the same script  (Read 6385 times)

Artifact

  • Newbie
  • *
  • Posts: 9
    • View Profile
Animating multiple sprites with the same script
« on: February 16, 2012, 06:52:05 pm »
Hello, I need some help animating 2 sprites with the same script. Right now I have 2 enemy sprites I wan't to animate with the same script. The method that moves and animates them looks like this:

Code: [Select]
    void MoveToPlayer()
    {
        if (enemyTransform.localPosition.x >= player.transform.localPosition.x)
        {
            enemySpeed = 5;
            enemyTransform.Translate(Vector3.left * amountToMove, Space.World);
            anim.Play("WalkLeft");

        }
        else if (enemyTransform.localPosition.x <= player.transform.localPosition.x)
        {
            enemySpeed = 5;
            enemyTransform.Translate(Vector3.right * amountToMove, Space.World);
            anim.Play("WalkRight");
           
        }
    }

The problem is that if I add this script to both my sprites it only animates one of them, the other just moves without any animation. Some help with this issue would really be appreciated.

Thanks in advance :)

« Last Edit: February 16, 2012, 06:54:59 pm by Artifact »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Animating multiple sprites with the same script
« Reply #1 on: February 16, 2012, 09:27:23 pm »
It looks like you're only animating one of the sprites (anim.Play()). You will need to call anim.Play(...) on the other sprite too.

Artifact

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Animating multiple sprites with the same script
« Reply #2 on: February 17, 2012, 12:19:25 am »
I solved the issue, my tk2dAnimatedSprite was static, thats why it only reacted on one of my sprites....

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Animating multiple sprites with the same script
« Reply #3 on: February 17, 2012, 06:55:58 am »
Ah that makes sense - no way to tell from the snippet you posted though! Glad you've resolved the issue.
« Last Edit: February 17, 2012, 06:59:53 am by unikron »