2D Toolkit Forum

2D Toolkit => Support => Topic started by: Kenzo on July 23, 2013, 07:55:26 pm

Title: Cannot able to play animation
Post by: Kenzo 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 : (http://s18.postimg.org/z3u7wh24p/error.jpg)
Title: Re: Cannot able to play animation
Post by: unikronsoftware 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 :)
Title: Re: Cannot able to play animation
Post by: Kenzo on July 23, 2013, 08:02:38 pm
Ahh thank you so much !  ;)