【问题标题】:Replacing Unity Time.time with a counter incremented by 100?用递增 100 的计数器替换 Unity Time.time?
【发布时间】:2019-05-01 05:09:16
【问题描述】:

我遇到过这样一种情况,如果 Time.time 在 Update() 中不同通道的两个不同位置调用,则值会有所不同 因此,在其增量中,任何使用 Vector3(0,Time.time,0) 都会导致 结果跳跃。我有一个开始路径的游戏对象 一段代码然后进一步转换到另一组代码 在脚本中。 Time.time 在第一次调用中的间隙执行和 第二个调用不同于第一个循环中的间隙 称呼。这就是为什么我要求更换。它与代码无关。它是关于两个 Time.time 用法之间的 Time.time 差异。我相信存在执行导致的差异。

    void Update () {

            synchTime = Time.time;
            // This proc releases gameobject from center into an outward spiralling trajectory till the height orbit path attained,
            // then disables itself releasing the gameobject into the sine wave orbital path.
            if (!reachedElevation)
            {
                transform.Translate(0, Time.deltaTime, 0);
                reachedElevation = true;
                _AgentY = Mathf.Sin(synchTime);//Keeps value started and in synch with usage below

            }else{

            // The trouble is making the 'Y' synch between where the spiral left off and this sine. It has to do with Time.time
            _AgentY = Mathf.Sin(synchTime);

            Debug.Log("Before transform.localPosition.y: " + transform.localPosition.y);
            transform.localPosition = new Vector3(transform.localPosition.x, _AgentY, transform.localPosition.z);
            Debug.Log("After transform.localPosition.y: " + transform.localPosition.y);

            } 
     }

【问题讨论】:

    标签: c unity3d time


    【解决方案1】:

    在更新调用开始时创建一个局部变量,并将其设置为 Time.time,然后您可以在更新中的任何位置引用此变量,并且它将保持不变。

    【讨论】:

    • 我添加了'else',删除了return();,把synchTime = Time.time;作为更新的第一行,删除了 synchTime 增量,更改为 _AgentY = Mathf.Sin(synchTime)。结果没有改变。 _AgentY 变量值仍有跳转。
    • 我也在编辑器中运行,没有编译。分析器显示 +75% 的编辑器使用率。到目前为止,我一直在努力避免编译和设备推送。我猜我只需要解决这个问题,继续我的游戏,然后推动查看真正的性能问题。我非常希望能够长期发展。这一点必须在某个时候越过。我确实更新了代码并添加了图像。跳转发生在“else”语句中。螺旋和正弦路径非常适合自己。
    猜你喜欢
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 2015-10-13
    • 2019-11-16
    • 2014-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多