我如何使用特定的速度变量进行缩放转换?

How can i scale transform with specific speed var?

IEnumerator scaleCube(Transform trans)
    {
        while (true)
        {
            trans.localScale += new Vector3(0.1f, 0.1f, 0);
            yield return null;
        }
    }

trans = 变换 我想以特定的速度缩放它。我的意思是使用新的 Vector3 但要让它更快。

在启动函数中

StartCoroutine(scaleCube(cube.transform));

我有一个 public 全局浮动速度变量。 究竟如何使用秤的速度变量来控制秤的速度?

创建一个速度变量,然后乘以 Time.deltaTime。就这么简单。

public float speed = 2f;

IEnumerator scaleCube(Transform trans)
{
    while (true)
    {
        trans.localScale += new Vector3(speed * Time.deltaTime, speed * Time.deltaTime, 0);
        yield return null;
    }
}

当您增加 speed 变量的值时,缩放速度会加快。