持续延迟

问题描述 投票:0回答:1

我有一个脚本,当弹丸首先进入对撞机时实例化预制体,然后为使用Lerps进入对撞机的接下来的四个弹丸中的每一个增加该预制体的比例。

第一次运行此代码时插值很好。但是每次之后,第一个Lerp功能都会有一个延迟。如何解决这个尴尬的暂停?

An example gif of the problem

private void OnTriggerEnter(Collider other)
{
    if(other.CompareTag("Projectile"))
    {
        catchCount++;
    }
}

void CatchAndRelease()
{
    proj = GameObject.Find("ReleaseObj(Clone)");

    switch (catchCount)
    {
        case 0:
            if(isInstantiated == true)
            {
                catchCount = 0;
            }
            break;
        case 1:
            if(isInstantiated == false)
            {
                Instantiate(releaseObj, transform.position, Quaternion.identity, gameObject.transform.parent);
                isInstantiated = true;
            }
            break;
        case 2:
            Vector3 scaleUp = new Vector3(1.5f, 1.5f, 1.5f);
            proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp, Time.deltaTime);
            break;
        case 3:
            Vector3 scaleUp2 = new Vector3(2f, 2f, 2f);
            proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp2, Time.deltaTime);
            break;
        case 4:
            Vector3 scaleUp3 = new Vector3(2.5f, 2.5f, 2.5f);
            proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp3, Time.deltaTime);
            break;
        case 5:
            Vector3 scaleUp4 = new Vector3(3f, 3f, 3f);
            proj.transform.localScale = Vector3.Lerp(proj.transform.localScale, scaleUp4, Time.deltaTime);

            break;
        case 6:
            if(isInstantiated == false)
            {
                catchCount = 0;

            }
            else
            {
                catchCount = 6;
            }
            break;

}

对于C#还是很新的,非常感谢您的帮助或建议!

unity3d lerp
1个回答
0
投票
Lerp是线性的。上面的代码的问题在于,第一个参数transform.position会更改每帧。这里有一些使用Lerp的更好方法的链接:
© www.soinside.com 2019 - 2024. All rights reserved.