1
Support / Re: Problem with setting a library dynamically
« on: August 21, 2013, 12:47:11 pm »
yes i had the correct Object.
I solved the problem changing GetComponentInChildren for GetComponent.
I thought the first one look in all the parent and children, in fact in the other gameObject works to pick the tk2dSpriteAnimator
Thank you very much the final code is this : maybe could be useful for future readers
private var tkScript : tk2dSpriteAnimator;
private var dataGo : tk2dSpriteAnimation;
var go : GameObject;
function Start () {
//store the script tk2dSpriteAnimator to manipulate
tkScript = gameObject.GetComponentInChildren (tk2dSpriteAnimator);
//Load the Collection we want to load through the gameObject . Has to be in Resources folder
go = Resources.Load("AlienBlueAnim", typeof(GameObject)) as GameObject;
if (go != null) {
UnityEditor.Selection.activeGameObject = go;
Debug.Log ("getting " + go);
}
else {
Debug.Log("Not found. Are you sure its in resources?");
}
//pick the Animation component to set the library
dataGo = go.GetComponent(tk2dSpriteAnimation);
if (dataGo != null)
{
Debug.Log ("el valor de dataGo es" + dataGo);
}
else
{
Debug.Log ("not found the spriteanimation");
}
//set the library
tkScript.Library = dataGo;
//set the clip
tkScript.Play("AlienBlue1");
I solved the problem changing GetComponentInChildren for GetComponent.
I thought the first one look in all the parent and children, in fact in the other gameObject works to pick the tk2dSpriteAnimator
Thank you very much the final code is this : maybe could be useful for future readers
private var tkScript : tk2dSpriteAnimator;
private var dataGo : tk2dSpriteAnimation;
var go : GameObject;
function Start () {
//store the script tk2dSpriteAnimator to manipulate
tkScript = gameObject.GetComponentInChildren (tk2dSpriteAnimator);
//Load the Collection we want to load through the gameObject . Has to be in Resources folder
go = Resources.Load("AlienBlueAnim", typeof(GameObject)) as GameObject;
if (go != null) {
UnityEditor.Selection.activeGameObject = go;
Debug.Log ("getting " + go);
}
else {
Debug.Log("Not found. Are you sure its in resources?");
}
//pick the Animation component to set the library
dataGo = go.GetComponent(tk2dSpriteAnimation);
if (dataGo != null)
{
Debug.Log ("el valor de dataGo es" + dataGo);
}
else
{
Debug.Log ("not found the spriteanimation");
}
//set the library
tkScript.Library = dataGo;
//set the clip
tkScript.Play("AlienBlue1");