Cod*_*ang 0 c# unity-game-engine itween
我正在开发 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");
}
Run Code Online (Sandbox Code Playgroud)
但是我在控制台中看不到“完成”。
Unity Answers 上的这篇文章描述了您遇到问题的原因:
默认情况下,iTween 会尝试调用您在它正在设置动画的对象上提供的回调方法 - 在您的情况下是
mainCamera.gameObject. 由于“onCameraShakeComplete”不驻留在该对象上,因此永远不会被调用。您有两个选择:将该方法移到您的方法上,mainCamera.gameObject或者简单地提供 am "onCompleteTarget" ofgameObject来告诉 iTween 使用设置此 iTween 的游戏对象。
在您的情况下,它正在设置动画的对象是newBoom,但是您在自己的组件上有回调。要使 iTween 使用您当前的回调,您可以在Hash调用中添加一个参数:
iTween.MoveTo (newBoom, iTween.Hash(
// ...
"oncomplete", "BoomComplete",
"oncompletetarget", gameObject
));
Run Code Online (Sandbox Code Playgroud)