ITween指定方法执行者
ITween可以在动画开始、中间及结束时指定某个物体(默认是执行动画的物体)执行某个方法:
例如:
在一个Cube上挂载如下脚本:
public GameObject sphere;
private void Start()
{
iTween.MoveTo(gameobject, iTween.Hash("position", Vector3.forward * 3f, "oncomplete", "TestPos", "oncompletetarget", sphere, "speed", 1));
}
则动画执行完毕后,会执行挂载在sphere上的TestPos()方法。
如在Cube上执行动画即指定sphere为动画物体,则无需oncompletetarget参数:
public GameObject sphere;
private void Start()
{
iTween.MoveTo(sphere, iTween.Hash("position", Vector3.forward * 3f, "oncomplete", "TestPos", "speed", 1));
}
附加说明
1.指定方法TestPos可以为private类型,且无需指定脚本名称,只需方法名;
2.感觉动画完成后有点延迟才执行方法;
3.关于ITween.Hash中的参数名可参阅官网:http://www.pixelplacement.com/itween/documentation.php