2D Toolkit Forum
2D Toolkit => Support => Topic started by: tunahantolga on July 29, 2013, 10:06:09 am
-
Hi,
I want to trigger an animation(tk2d Animated Sprite) also I have a shaman and gold on screen.When gold touched a shaman, gold is destroyed but I can't see animation.I want to gold touched a shaman, gold is destroy and "golddestroy" animation.
I take it my shaman object is "goldshaman" tag and animated sprite,shaman and gold has a sphere collider and trigger is a selected.
I take a one error. Error is a " NullReferenceException: Object reference not set to an instance of an object"
Here is the code:
public class col : MonoBehaviour {
tk2dAnimatedSprite animSprite;
// Use this for initialization
void Start () {
animSprite = GetComponent<tk2dAnimatedSprite>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag == "goldshaman")
{
animSprite.Play("golddestroy");
}
}
}
Please help me
Thank you :)
-
What version of tk2d are you using? Do you actually have a tk2dAnimatedSprite in your gameobject? Or is it a tk2dSpriteAnimator (tk2d 2.1 and above)?
-
Normally, I am using 2.00 version tk2d but I make a update now. I didn't add Sprite With Animator on screen. Should I add?
-
Debug.Log(animSprite);
is it null? If its null you need to work out why its null.
-
Yep, I take a error. "NullReferenceException:Object reference not set to an instance of an object"
-
That means you're not getting the correct gameobject. Click on the gameobject that is causing the trigger, and look at the values in the inspector. can you see a tk2dAnimatedSprite component?
-
I take a 2 error.
Firstly : Unable to find clip 'golddestroy' in library,
secondly : Calling clip.Play() with a null clip.
-
Is there a clip "golddestroy" in the library? Make sure the spelling is the same, and there aren't any spaces, etc.
You can print animSprite.Library.clips to verify.
-
Yeah, animation is working but my not just thing.When gold touched shaman, gold is destroy and working animation.Also animation just as gold working.So animation is move to y axis always.
When gold touched shaman, animation Tk 2d Sprite changes instead of gold.
-
I don't think I understand what is going on. Can you zip up your project and email to support at unikronsoftware.com please?