Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 统一-反射和反射(取决于标签)激光更新每个帧?_Unity3d_Unityscript_Raycasting - Fatal编程技术网

Unity3d 统一-反射和反射(取决于标签)激光更新每个帧?

Unity3d 统一-反射和反射(取决于标签)激光更新每个帧?,unity3d,unityscript,raycasting,Unity3d,Unityscript,Raycasting,我用光线投射反射和线渲染器尝试了几种不同的方法,但似乎都不能正常工作。这一个,唯一一个半工作的,只在开始时设置自己,从不为移动的对象更新;它变得非常不稳定,扭曲,上下轻微扭曲,严重扭曲,没有折射,不用麻烦指出。有什么想法吗?我已经在这上面呆了很长时间了 不按照我尝试做的示例的要求工作,全新的代码是一个可行的选择: @script RequireComponent(LineRenderer) private var goTransform:Transform; private var lineR

我用光线投射反射和线渲染器尝试了几种不同的方法,但似乎都不能正常工作。这一个,唯一一个半工作的,只在开始时设置自己,从不为移动的对象更新;它变得非常不稳定,扭曲,上下轻微扭曲,严重扭曲,没有折射,不用麻烦指出。有什么想法吗?我已经在这上面呆了很长时间了

不按照我尝试做的示例的要求工作,全新的代码是一个可行的选择:

@script RequireComponent(LineRenderer)

private var goTransform:Transform;
private var lineRenderer:LineRenderer;

private var ray:Ray;
private var hit:RaycastHit;
private var inDirection:Vector3;
public var nReflections:int = 2;
private var nPoints:int;


function Awake () 
{
    goTransform = this.GetComponent(Transform);
    lineRenderer = this.GetComponent(LineRenderer);
}

function Update () {
    nReflections = Mathf.Clamp(nReflections,1,nReflections);
    ray = new Ray(goTransform.position,goTransform.forward);

    Debug.DrawRay (goTransform.position,goTransform.forward * 100, Color.magenta);

    nPoints = nReflections;
    lineRenderer.SetVertexCount(nPoints); 
    lineRenderer.SetPosition(0,goTransform.position);

    for(var i:int=0;i<=nReflections;i++) {
       if(i == 0) {
         if(Physics.Raycast(ray.origin,ray.direction, hit, 100)) {  
          if(hit.transform.CompareTag("LaserReflector")) {
              inDirection = Vector3.Reflect(ray.direction, hit.normal);
              ray = new Ray(hit.point,inDirection);

              Debug.DrawRay (hit.point, hit.normal*3, Color.blue);
              Debug.DrawRay (hit.point, inDirection*100, Color.magenta);

              Debug.Log("Object name: " + hit.transform.name);

              if(nReflections==1)
              {
                 lineRenderer.SetVertexCount(++nPoints); 
              }

              lineRenderer.SetPosition(i+1, hit.point);
          } 
         }
       }
       else
       {
         if(Physics.Raycast(ray.origin,ray.direction, hit, 100)) {
          if(hit.transform.CompareTag("LaserReflector")) {
              inDirection = Vector3.Reflect(inDirection, hit.normal);
              ray = new Ray(hit.point, inDirection);

              Debug.DrawRay (hit.point, hit.normal*3, Color.blue);
              Debug.DrawRay (hit.point, inDirection*100, Color.magenta);

              Debug.Log("Object name: " + hit.transform.name);

              lineRenderer.SetVertexCount(++nPoints); 
              lineRenderer.SetPosition(i+1,hit.point);
          } 
         }
       }
    }
}