Hello Guest

Author Topic: Cannot able to play animation  (Read 3767 times)

Kenzo

  • Newbie
  • *
  • Posts: 10
    • View Profile
Cannot able to play animation
« on: July 23, 2013, 07:55:26 pm »
Hi all,
I've created a clip named Right, it gives NullReferenceException : Object reference not set to an instance of an object error

Here is the code :
Code: [Select]
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {


tk2dAnimatedSprite anim;
 

// Use this for initialization
void Start () {

anim = GetComponent<tk2dAnimatedSprite> ();
}

// Update is called once per frame
void Update () {

if (!anim.IsPlaying ("Right"))
anim.Play("Right");

}
}

simply can't work why? 
Please help guys.
Best regards.



image for my case :

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Cannot able to play animation
« Reply #1 on: July 23, 2013, 08:00:39 pm »
You're mixing up 2D Toolkit 2.0 & 1.9x -
The tk2dAnimatedSprite has been replaced by a tk2dSpriteAnimator - you can tell from the list of components on your gameobject.
You can pretty much replace tk2dAnimatedSprite -> tk2dSpriteAnimator in your script with this and everything will be good :)

Kenzo

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Cannot able to play animation
« Reply #2 on: July 23, 2013, 08:02:38 pm »
Ahh thank you so much !  ;)