[]获取lh动画控制失败【已解决】
//方法一:直接异步加载
var layaMonkey:Sprite3D = scene.addChild(Sprite3D.load(url+"LayaScene_sharedunity/sharedunity.lh")) as Sprite3D;
var zombieAnimator:Animator =layaMonkey.getChildAt(0).getComponentByType(Animator) as Animator;
zombieAnimator.clip.islooping = true;
zombieAnimator.stop();
错误提示:TypeError: Cannot read property 'getComponentByType' of undefined
看例程关于层级的不是很详细,自己也不是很理解这个关系,麻烦给看下是什么问题呢,谢谢。
以是LH文件内容:
{
"type":"Sprite3D",
"props":{
"name":"sharedunity"
},
"customProps":{
"translate":[
0,
0,
0
],
"rotation":[
0,
0,
0,
-1
],
"scale":[
1,
1,
1
]
},
"child":[
{
"type":"MeshSprite3D",
"props":{
"isStatic":false,
"name":"share"
},
"customProps":{
"layer":0,
"translate":[
0,
0,
0
],
"rotation":[
0.7071068,
0,
0,
-0.7071068
],
"scale":[
1,
1,
1.5
],
"meshPath":"Assets/share-Sphere001.lm",
"materials":[
{
"type":"Laya.BlinnPhongMaterial",
"path":"Resources/unity_builtin_extra.lmat"
}
]
},
"components":{
"Rigidbody":{},
"Animator":{
"clipPaths":[
"Assets/shared-shared.lani"
],
"playOnWake":true
}
},
"child":
},
{
"type":"Camera",
"props":{
"isStatic":false,
"name":"Main Camera",
"clearFlag":1,
"orthographic":false,
"fieldOfView":29,
"nearPlane":0.1,
"farPlane":100
},
"customProps":{
"layer":0,
"translate":[
-1.49,
1.58,
-6.84
],
"rotation":[
0,
1,
0,
0
],
"scale":[
1,
1,
1
],
"viewport":[
0,
0,
1,
1
],
"clearColor":[
1,
1,
1,
0
],
"skyBox":{
"sharedMaterial":{}
}
},
"components":{},
"child":
},
{
"type":"DirectionLight",
"props":{
"isStatic":false,
"name":"Directional Light",
"intensity":1,
"lightmapBakedType":0
},
"customProps":{
"layer":0,
"translate":[
-1.17,
2.2,
-0.39
],
"rotation":[
0.1093816,
0.8754261,
0.4082179,
-0.2345697
],
"scale":[
1,
1,
1
],
"color":[
1,
1,
1
]
},
"components":{},
"child":
}
]
}
var layaMonkey:Sprite3D = scene.addChild(Sprite3D.load(url+"LayaScene_sharedunity/sharedunity.lh")) as Sprite3D;
var zombieAnimator:Animator =layaMonkey.getChildAt(0).getComponentByType(Animator) as Animator;
zombieAnimator.clip.islooping = true;
zombieAnimator.stop();
错误提示:TypeError: Cannot read property 'getComponentByType' of undefined
看例程关于层级的不是很详细,自己也不是很理解这个关系,麻烦给看下是什么问题呢,谢谢。
以是LH文件内容:
{
"type":"Sprite3D",
"props":{
"name":"sharedunity"
},
"customProps":{
"translate":[
0,
0,
0
],
"rotation":[
0,
0,
0,
-1
],
"scale":[
1,
1,
1
]
},
"child":[
{
"type":"MeshSprite3D",
"props":{
"isStatic":false,
"name":"share"
},
"customProps":{
"layer":0,
"translate":[
0,
0,
0
],
"rotation":[
0.7071068,
0,
0,
-0.7071068
],
"scale":[
1,
1,
1.5
],
"meshPath":"Assets/share-Sphere001.lm",
"materials":[
{
"type":"Laya.BlinnPhongMaterial",
"path":"Resources/unity_builtin_extra.lmat"
}
]
},
"components":{
"Rigidbody":{},
"Animator":{
"clipPaths":[
"Assets/shared-shared.lani"
],
"playOnWake":true
}
},
"child":
},
{
"type":"Camera",
"props":{
"isStatic":false,
"name":"Main Camera",
"clearFlag":1,
"orthographic":false,
"fieldOfView":29,
"nearPlane":0.1,
"farPlane":100
},
"customProps":{
"layer":0,
"translate":[
-1.49,
1.58,
-6.84
],
"rotation":[
0,
1,
0,
0
],
"scale":[
1,
1,
1
],
"viewport":[
0,
0,
1,
1
],
"clearColor":[
1,
1,
1,
0
],
"skyBox":{
"sharedMaterial":{}
}
},
"components":{},
"child":
},
{
"type":"DirectionLight",
"props":{
"isStatic":false,
"name":"Directional Light",
"intensity":1,
"lightmapBakedType":0
},
"customProps":{
"layer":0,
"translate":[
-1.17,
2.2,
-0.39
],
"rotation":[
0.1093816,
0.8754261,
0.4082179,
-0.2345697
],
"scale":[
1,
1,
1
],
"color":[
1,
1,
1
]
},
"components":{},
"child":
}
]
}
没有找到相关结果
已邀请:
3 个回复
zwy363
赞同来自:
layaMonkey.once(Event.HIERARCHY_LOADED, this, function():void{
//获取Animator动画组件
var zombieAnimator = (layaMonkey.getChildAt(0) as Sprite3D).getComponentByType(Animator) as Animator;
zombieAnimator.clip.islooping = true;
zombieAnimator.stop();
});
老是在文档和例程里被不同内容误导。。。什么时候能整合一下,把文档和例程里的东西~~
我弄好啦。
qian
赞同来自:
Aar0n
赞同来自: