2D Toolkit Forum

2D Toolkit => Support => Topic started by: tunahantolga on July 29, 2013, 10:06:09 am

Title: Trigger Animation doesn't work, please help me.
Post 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  :)
Title: Re: Trigger Animation doesn't work, please help me.
Post by: unikronsoftware on July 29, 2013, 11:31:34 am
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)?
Title: Re: Trigger Animation doesn't work, please help me.
Post by: tunahantolga on July 29, 2013, 12:06:23 pm
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?

Title: Re: Trigger Animation doesn't work, please help me.
Post by: unikronsoftware on July 29, 2013, 12:15:35 pm
Debug.Log(animSprite);
is it null? If its null you need to work out why its null.

Title: Re: Trigger Animation doesn't work, please help me.
Post by: tunahantolga on July 29, 2013, 12:38:17 pm
Yep, I take a error. "NullReferenceException:Object reference not set to an instance of an object"
Title: Re: Trigger Animation doesn't work, please help me.
Post by: unikronsoftware on July 29, 2013, 01:01:20 pm
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?
Title: Re: Trigger Animation doesn't work, please help me.
Post by: tunahantolga on July 29, 2013, 02:06:30 pm
I take a 2 error.
Firstly : Unable to find clip 'golddestroy' in library,   
secondly : Calling clip.Play() with a null clip.
 
Title: Re: Trigger Animation doesn't work, please help me.
Post by: unikronsoftware on July 29, 2013, 02:17:24 pm
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.
Title: Re: Trigger Animation doesn't work, please help me.
Post by: tunahantolga on July 29, 2013, 03:39:09 pm
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.
Title: Re: Trigger Animation doesn't work, please help me.
Post by: unikronsoftware on July 29, 2013, 04:02:43 pm
I don't think I understand what is going on. Can you zip up your project and email to support at unikronsoftware.com please?