Hello Guest

Author Topic: Scripting Animation according to documentation problems  (Read 5557 times)

sneenlantern

  • Newbie
  • *
  • Posts: 2
    • View Profile
Scripting Animation according to documentation problems
« on: April 16, 2012, 12:19:47 pm »
Hi, forgive me if this is stupid, I'm new to both 2d Toolkit and Unity.  But I followed the documentation exactly until it came to scripting the animation and I made some changes and I'm not sure if I made them correctly or if I made enough.  This is what the result looks like:



As you can see on the left there's no sprite, and when you run the game it's just a gray square.  This is my code I'm running:

using System.Collections;

public class TutorialAnimController : MonoBehaviour
{
   tk2dAnimatedSprite anim;

   // Use this for initialization
   void Start () {
      anim = GetComponent<tk2dAnimatedSprite>();
   }

   bool walking = false;

   void HitCompleteDelegate(tk2dAnimatedSprite sprite, int clipId)
   {
      if (walking)
      {
         anim.Play("walk");
      }
      else
      {
         anim.Play("idle");
      }
   }

   // Update is called once per frame
   void Update ()
   {
      if (Input.GetKeyDown(KeyCode.F))
      {
         anim.Play("hit");
         anim.animationCompleteDelegate = HitCompleteDelegate;
      }
         if (Input.GetKeyDown(KeyCode.Space))
      {
         anim.Play("jump");
         anim.animationCompleteDelegate = null;
         walking = false;
      }
      if (Input.GetKeyDown(KeyCode.RightArrow))
      {
         anim.Play("walk");
         anim.animationCompleteDelegate = null;
         walking = true;
      }
      
      if (Input.GetKeyDown(KeyCode.LeftArrow))
      {
         anim.Play("walkleft");
         anim.animationCompleteDelegate = null;
         walking = true;
      }
   }
}


Has anyone got the time to take a look at this and tell me what I'm doing wrong?  Should I be naming the animation somewhere in the script?  I'm not now.  Should I even be doing this in scripting?  Should I be doing this in Playmaker or something?  I just tried to follow the documentation. 

Please help.  Thanks for reading. 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scripting Animation according to documentation problems
« Reply #1 on: April 16, 2012, 01:59:17 pm »
Hi,

This looks like the material has lost the reference to the texture...
Can you double click on atlas0_material which you can see in the Mesh Renderer, and post a screenshot of that?

Alternatively, delete the atlas0_material object, open up the sprite collection editor and click Commit to regenerate this data.

sneenlantern

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Scripting Animation according to documentation problems
« Reply #2 on: April 16, 2012, 05:03:54 pm »
thanks, Unikron, that was it.  I really appreciate your help.  I'll be back for the next problem later.   ;)