Hello Guest

Author Topic: tk2dSpriteAnimator & Tagged GameObjects  (Read 3700 times)

chenklein

  • Newbie
  • *
  • Posts: 6
    • View Profile
tk2dSpriteAnimator & Tagged GameObjects
« on: July 27, 2013, 08:38:41 pm »
i have a script (Item) attached to a tk2dSpriteAnimator called Groopy, telling it to play one animation (randomly between "good" and "bad")
and i have a script (Game) that every few seconds instantiate a Groopy  at the door, if the groopy wasn't killed it renames it (by tagging) and then moves the Groopy to a different location.

this is how the Game script looks like -
 
var prefabs : GameObject[];

 var go : GameObject = Instantiate(prefabs[selectedItem] ,Vector3(-6.536877, 0, -0.1),Quaternion.identity);   
     if ((GroopyCount == 1) && (Item.ClipName == "Good"))
           {
           
            go.tag = "GroopyOnSide";
                 var GroopyOnSideClone : GameObject = GameObject.FindGameObjectWithTag("GroopyOnSide");
                 var GroopyOnSidePosition:float = GroopyOnSideClone.transform.position.x;
                 go.transform.position.x = 4;
     
                }


now i want to make the GroopyOnSideClone play a different animation without interfering the Item script that tells the Groopy to play the "good" or "bad" animations at the door.

i tried - GroopyOnSideClone.Play ("BadOnSide")
but unity recognize GroopyOnSideClone as game object and not a tk2dSpriteAnimator so i get an error.

i also tried AddComponent and wrote this function to the Item script -

function ControlGroopiesOnSide ()
{

    var GroopyOnSideObject : GameObject = GameObject.FindGameObjectWithTag("GroopyOnSide");
    var GroopyOnSideAnim:tk2dSpriteAnimator = GroopyOnSideObject.AddComponent(tk2dSpriteAnimator);
    GroopyOnSideAnim.Play ("BadOnSide");
}

but got the error "MissingFieldException: Field 'tk2dSpriteAnimator.Libary' not found."

so my question is - is it possible to tell the same tk2dSpriteAnimator to play different animations to different tagged objects and if so how do i do it.   

thanks!   

chen

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSpriteAnimator & Tagged GameObjects
« Reply #1 on: July 27, 2013, 09:39:04 pm »
After you get the gameObject, you can easily get the component using gameObject.GetComponent<t2kdSpriteAnimator>(). That should work...

chenklein

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: tk2dSpriteAnimator & Tagged GameObjects
« Reply #2 on: August 02, 2013, 02:41:32 pm »
so its GetComponent -  not AddComponent...

works !!  thank you