Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - chenklein

Pages: [1]
1
Support / Re: tk2dSpriteAnimator & Tagged GameObjects
« on: August 02, 2013, 02:41:32 pm »
so its GetComponent -  not AddComponent...

works !!  thank you

2
Support / 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

3
OOk , finally got it!

this is my code - its attached to a sprite with animator and in the inspector in the "anim" variable i've attached the same sprite animator

var anim : tk2dSpriteAnimator;
var ListOfClips:tk2dSpriteAnimationClip[];
ListOfClips = anim.Library.clips;

function Start ()
{
PlayRandomAnimation () ;
}

function PlayRandomAnimation ()
{
var RandomClipNumber:int = Random.Range(0 , ListOfClips.Length);
anim.Play(ListOfClips[RandomClipNumber]);
}


thank you very much midasmax and unikronsoftware 

4
Im sorry but i am not familiar with the new version of 2d toolkit and don't fully understand haw to use and code the sprite animator.
i keep getting this error  -  "NullReferenceException: Object reference not set to an instance of an object "
guess ill need to dig deeper in the 2D Toolkit Documentation.

5
hey

so - i did what u wrote me to do (without the rendomize part) just to get the list of clips , i've add this code to my animated sprite and it looks like this -

var anim : tk2dSpriteAnimator;
anim = GetComponent(tk2dSpriteAnimator);
var ListOfClips:tk2dSpriteAnimationClip[] = anim.Library.clips;


function Update ()
{
print (ListOfClips);
}

then i attached the same animated sprite to the variable anim in the inspector but i keep getting this arrow -

"NullReferenceException: Object reference not set to an instance of an object "

what am i doing wrong?? :-\

6
Hello  :D

Im trying to make an array of the animations in one animated sprit so that I can randomize between them by name. Haw do I access these animations in JavaScript ?

Thanks

Pages: [1]