private Vector3 targetPosition = new Vector3(-1.9f, -4, 0);
private Vector3 originPosition = new Vector3(0, -4, 0);
private Vector3 currentVelocity = Vector3.zero;
private bool move;
private void OnEnable()
{
move = false;
// 由於每一個帶有動畫的模型都需要各自的光照,故添加此動態調節的光照
var light = UtilsSearch.FindComponentChild<Light>(GameObject.FindGameObjectWithTag(StaticData.LightSystemTag).transform, StaticData.LightSourceName);
light.intensity = 0.5f;
}
private void LateUpdate()
{
if (move)
{
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref currentVelocity, 1);
}
if (!move)
{
transform.position = Vector3.SmoothDamp(transform.position, originPosition, ref currentVelocity, 1);
}
}
/// <summary>
/// 動態移動模型
/// </summary>
public void MoveStart()
{
move = true;
}
/// <summary>
/// 模型歸位
/// </summary>
public void MoveEnd()
{
move = false;
}
Unity學習筆記010.平滑移動
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.