Camera mainCamera = GameObject.Find("Main Camera").GetComponent();
Camera uiCamera = GameObject.Find("UICamera").GetComponent();
Vector3 startPos = mainCamera.WorldToScreenPoint(startTarget.transform.position);//先转换到屏幕坐标
Vector3 endPos = endTarget.transform.position;
startPos = uiCamera.ScreenToWorldPoint(startPos);//再转换到对象所在的Camera坐标系
target.transform.position = startPos;
Sequence seq = DOTween.Sequence();
seq.Append(target.transform.DoMove(endPos,1f,false));
seq.SetAutoKill(false);
seq.Play();
Animator animator = this.GetComponent();
RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController;
AnimationClip[] clips = runtimeAnimatorController.animationClips;
AnimationClip clip = null;
if (clips.Length > 0)
{
for (int i = 0; i < clips.Length; i++)
{
AnimationClip temp = clips[i];
AnimationEvent aniEvent = new AnimationEvent();
aniEvent.time = clip.length;
aniEvent.functionName = "ActionEnd";
clip.AddEvent(aniEvent);
}
}
GameObject obj = new GameObject();
Text testLab = obj.AddComponent();
testLab.font = Font.CreateDynamicFontFromOSFont("Arial",22);
testLab.text = "hello world";
testLab.fontStyle = FontStyle.BoldAndItalic;
testLab.fontSize = 35;
obj.layer = this.gameObject.layer;
obj.transform.SetParent(this.transform,false);