为什么统一渲染器不更新?

时间:2018-09-10 07:08:23

标签: c# unity3d

我试图从摄像机到实例化对象画一条线,我使用场景UnityARHitTest示例。当我在垂直平面上触摸时,该对象被实例化,我想从摄像机到对象画一条线。 strong>当我移动设备时,该行应从相机的中心显示。出于某种原因,在后期更新中调用该行时,渲染器未显示。

    LineRenderer lins;
    public GameObject Lineprefab;

bool HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes)
{
    List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest (point, resultTypes);
    if (hitResults.Count > 0 && check==true) 
    {
        foreach (var hitResult in hitResults) 
        {
            Debug.Log ("Got hit!");

            if (Select == 0)
            {
                Debug.Log("hit-zero!");
                Instantiate(Instaobj[0], ForSelect);
                check = false;
            }

            if (Select == 1)
            {
                Debug.Log("hit-one!");
                Instantiate(Instaobj[1], ForSelect);
                check = false;
            }

            if (Select == 2)
            {
                Debug.Log("hit-two!");
                Instantiate(Instaobj[2], ForSelect);
                check = false;
            }

            if (Select == 3)
            {
                Debug.Log("hit-three!");
                Instantiate(Instaobj[3], ForSelect);
                check = false;
            }

            if (Select == 4)
            {
                Debug.Log("hit-four!");
                Instantiate(Instaobj[4], ForSelect);
                check = false;
            }

            if (Select == 5)
            {
                Debug.Log("hit-five!");
                Instantiate(Instaobj[5], ForSelect);
                check = false;
            }

            m_HitTransform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform);
            m_HitTransform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);
            Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));

            obj.StopPlaneTracking();
            if (GameObject.Find("debugPlanePrefab(Clone)"))
                GameObject.Find("debugPlanePrefab(Clone)").SetActive(false);
            else
                Debug.Log("no prefab");


            //lins.SetPosition(0, m_HitTransform.position);
            //lins.SetPosition(1, obj.m_camera.transform.position);

            return true;
        }
    }
    return false;
}

当我在上面的方法中使用lins.setposition()时(注释),输出中显示一行。当我在下面的LateUpdate()中使用lins.setposition()时,输出未显示没有任何结果。

private void Start()
{
    spawngenerator();
}

void spawngenerator()
{
    GameObject newline = Instantiate(Lineprefab);
    lins = newline.GetComponent<LineRenderer>();
    //lins.SetPosition(0, m_HitTransform.position);
    //lins.SetPosition(1, obj.m_camera.transform.position);
}


private void LateUpdate()
{
    lins.SetPosition(0,obj.m_camera.transform.position );
    lins.SetPosition(1,m_HitTransform.position );
}

0 个答案:

没有答案