?讓一個物體從當前位置移動到另一個位置
?Vector3-Lerp - Unity 腳本 APIhttps://docs.unity.cn/cn/current/ScriptReference/Vector3.Lerp.html
1.在場景中新建兩個 Cube 立方體,在 Scene 視圖中將兩個 Cude的位置錯開。
?2.新建 C# 腳本 MoveToTarget.cs(寫完記得保存)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveToTarget : MonoBehaviour
{
public Transform endTrans; //定義結(jié)束位置的 Transform 對象
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//腳本所在位置緩動到 endTrans 的位置
transform.position = Vector3.Lerp(transform.position, endTrans.position, Time.deltaTime);
}
}
3.將腳本綁定到 Cude 上,然后將其 Inpector 視圖中將 endTrans 指定為 Cube(1) (我命名的是Arm)。(讓A緩動到B,就把腳本綁定在A上,endTrans 設(shè)置為 B)
文章來源:http://www.zghlxwxcb.cn/news/detail-742102.html
4.點擊播放按鈕,可以看到 Cube 緩動到 Cube(1)? (我的Arm)的位置文章來源地址http://www.zghlxwxcb.cn/news/detail-742102.html
到了這里,關(guān)于Unity3D 基礎(chǔ)——使用 Vector3.Lerp 實現(xiàn)緩動效果的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!