物体移动到目标位置
{
float step = speed * Time.deltaTime;
gameObject.transform.localPosition = Vector3.MoveTowards(gameObject.transform.localPosition, new Vector3(10, -3, 50), step);
}
插值
void Update ()
{
float step = speed * Time.deltaTime;
gameObject.transform.localPosition =new Vector3(Mathf.Lerp(gameObject.transform.localPosition.x, 10, step),
Mathf.Lerp(gameObject.transform.localPosition.y, -3, step),Mathf.Lerp(gameObject.transform.localPosition.z, 50, step));
}
iWeen
iTween.MoveTo(m_UIbgCamera, iTween.Hash("x", -20, "y", -3, "z", 50, "time", 1.0, "islocal", true ));
携程
StartCoroutine(MoveToPosition());
- IEnumerator MoveToPosition()
- {
- GameObject m_UIbgCamera = GameObject.Find(
"UI/FengMian/UIbgCamera"); while (m_UIbgCamera.transform.localPosition != new Vector3(-5, -3, 50))
- {
- m_UIbgCamera.transform.localPosition = Vector3.MoveTowards(m_UIbgCamera.transform.localPosition,
new Vector3(-20, -3, 50), 10 * Time.deltaTime);
yield return 0;
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步