我正在做一个Unity2游戏,我想让Boom在iTween动画的末尾消失。
以下是代码的一部分
void OnMouseDown() {
if (ChosePosition == false)
ChosePosition = true;
// make Star stop
else if (ChosePosition == true && ChoseForce == false) {
ChoseForce = true;
//Compute Force power
PowerDegree = Mathf.Abs (Star.transform.position.y - StarPosition)/ Mathf.Abs(StarendPosition - StarPosition) * 100;
//print (PowerDegree);
Vector3 NewBoomPostion = new Vector3 (Luncher.transform.position.x, BoomPosition, 85);
GameObject newBoom = Instantiate(Boom, NewBoomPostion , Quaternion.identity) as GameObject;
iTween.MoveTo (newBoom, iTween.Hash
("y",BoomPosition+((BoomendPosition-BoomPosition)/100*PowerDegree),
"speed",Boomspeed,
"EaseType",BoomeaseType,
"LoopType",BoomloopType,
"oncomplete","BoomComplete"
));
CarrierReset = true;
ChosePosition = false;
ChoseForce = false;
//After Shot, Luncher will move
iTween.Resume(Luncher);
//After Shot, Luncher Carrier will display
displayCarrierOrNot = true;
}
}
void BoomComplete(){
print("complete");
}但我在控制台上看不见“完全”。
发布于 2015-09-15 06:44:20
统一答案的这个职位描述了问题的原因:
默认情况下,iTween尝试调用回调方法,在它正在动画的对象上提供回调方法--在您的示例中是
mainCamera.gameObject。因为"onCameraShakeComplete“不驻留在该对象上,所以它永远不会被调用。您有两个选项:将该方法移到您的mainCamera.gameObject上,或者只需提供gameObject的am "onCompleteTarget“命令iTween使用正在设置此iTween的GameObject。
在您的示例中,它正在动画的对象是newBoom,但是在您自己的组件上有回调。要使iTween使用当前回调,可以向Hash调用添加一个参数:
iTween.MoveTo (newBoom, iTween.Hash(
// ...
"oncomplete", "BoomComplete",
"oncompletetarget", gameObject
));https://stackoverflow.com/questions/32579082
复制相似问题