我尝试了自己的方法,但无法获得有效的方法,下面是一个示例gif:https://gyazo.com/5cd4b74ee45240d3ff9ee13ae6ca6af6
这是该gif中使用的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public GameObject moving;
float lerpTime = 5f;
float currentLerpTime;
float moveDistance = 10f;
Quaternion startPos;
Quaternion endPos;
protected void Start()
{
startPos = moving.transform.rotation;
endPos = new Quaternion(0, 0, 0, 0);
}
protected void Update()
{
//reset when we press spacebar
if (Input.GetKeyDown(KeyCode.Space))
{
currentLerpTime = 0f;
}
//increment timer once per frame
currentLerpTime += Time.deltaTime;
if (currentLerpTime > lerpTime)
{
currentLerpTime = lerpTime;
}
//lerp!
float perc = currentLerpTime / lerpTime;
print(perc);
moving.transform.rotation = Quaternion.Lerp(startPos, endPos, perc);
}
}
它直到达到alpha 1才改变,我不确定为什么。 如果您知道为什么这样做,并且知道如何帮助我,请写评论。