C# 轨迹渲染器在传送时留下轨迹

C# 轨迹渲染器在传送时留下轨迹,c#,unity3d,C#,Unity3d,我有一个类似水果忍者的游戏,其中一把刀锋跟随你的手指,一个儿童轨迹渲染器跟随 这在编辑器中运行良好,但当我构建apk并在手机上播放时,它会从最后一点进行远程传输。因此,如果我在左上角移动,抬起手指并将其放在右下角,你会看到一条很细的快速对角线 这是我的密码: private void Update() { if (Event.current == null || (Event.current != null && EventSystem.current.currentSe

我有一个类似水果忍者的游戏,其中一把刀锋跟随你的手指,一个儿童轨迹渲染器跟随

这在编辑器中运行良好,但当我构建apk并在手机上播放时,它会从最后一点进行远程传输。因此,如果我在左上角移动,抬起手指并将其放在右下角,你会看到一条很细的快速对角线

这是我的密码:

private void Update()
{
    if (Event.current == null || (Event.current != null && EventSystem.current.currentSelectedGameObject == null))
    {
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            circleCollider.enabled = false;
            currentTrail = Instantiate(trail, transform);
            isCutting = true;
        }
        else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            circleCollider.enabled = false;
            currentTrail.transform.SetParent(null);
            Destroy(currentTrail, 2f);
            isCutting = false;
        }
    }

if (isCutting)
    {
        Vector2 newPos = currentTrail.transform.position = rb.position = cam.ScreenToWorldPoint(Input.mousePosition);

        float velocity = (newPos - previousPos).magnitude * Time.deltaTime;
        if (velocity > minCuttingVelocity)
        {
            circleCollider.enabled = true;
            canCut = true;
        } else {
            circleCollider.enabled = false;
            canCut = false;
        }

        previousPos = newPos;
    }
}

正如我在编辑中所说,这很好,只是在电话上。我能做些什么来回避这个问题吗?

当你想一想,在统一中,任何运动都只是每一帧的一个小传送。根据此逻辑,轨迹渲染器必须基于这种移动。轨迹渲染器如何区分大型传送站和小型传送站?可能不行


因此,如果要显式传送对象,请禁用其轨迹渲染,传送对象,然后重新启用它。我们应该做到这一点

您可以在传送之前使用
TrailRenderer.emitting=false停止追踪,然后在传送之后将其设置为true

只需检查新位置和旧位置之间的差异是否:

if(distance > notmalMovingDistance)
    myTrail.emitting = false;
else
    myTrail.emitting = true;

我试着在我的手机上运行相同的代码,当我点击周围的时候,它似乎无法传送。我想可能是因为不同的手机或其他原因,我不确定