1 LineRenderer lineRender = this.renderer as LineRenderer; 2 //0表明起始點,這裏是設置起始點position 3 lineRender.SetPosition (0,transform.position); 4 5 Ray ray = new Ray (transform.position,transform.forward); 6 RaycastHit hitInfo; 7 if(Physics.Raycast (ray, out hitInfo)) 8 { 9 //1表明終點,這裏設置終點位置 10 lineRender.SetPosition(1,hitInfo.point); 11 } 12 else 13 { 14 lineRender.SetPosition(1,transform.position + transform.forward * 100); 15 }