Unity3d 光线投射目标不随父对象移动,即使光线具有矢量方向

Unity3d 光线投射目标不随父对象移动,即使光线具有矢量方向,unity3d,c#-4.0,raycasting,Unity3d,C# 4.0,Raycasting,这怎么会发生?我已经多次重写了Raycast代码,但下面是当前的迭代: using System.Collections; using System.Collections.Generic; using UnityEngine; public class RaycastTest : MonoBehaviour { //width will control the distance of the two rays' direction from each other //ran

这怎么会发生?我已经多次重写了Raycast代码,但下面是当前的迭代:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RaycastTest : MonoBehaviour {

    //width will control the distance of the two rays' direction from each other
    //range will control the collision range
    public float width, range;
    //will take width and control bias in the furture
    float b;

    void Start()
    {

    }

    void Update () {
        //loop from negative one to positive one to add left and right rays in the future
        for (int i = -1; i < 3; i += 2)
        {
            //commented line segment showing how bias will work to control the angle of the ray
            //! cant do any of that yet because this ray doesn't work
            Ray ray = new Ray(transform.position, /*(transform.forward + transform.right/2 * i) / 3*/ transform.forward);
            RaycastHit hitInfo;

            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, range))
            {
                Debug.DrawLine(ray.origin, hitInfo.point, Color.red);
            }
            else
            {
                Debug.DrawLine(ray.origin, ray.direction * range, Color.green);
            }
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类测试:单行为{
//宽度将控制两条光线方向之间的距离
//范围将控制碰撞范围
公共浮动宽度、范围;
//将在未来采取宽度和控制偏差
浮球b;
void Start()
{
}
无效更新(){
//从负向循环到正向循环,以在将来添加左右光线
对于(int i=-1;i<3;i+=2)
{
//注释线段,显示偏移如何控制光线的角度
//!现在还不能这样做,因为这条光线不工作
光线=新光线(transform.position,/*(transform.forward+transform.right/2*i)/3*/transform.forward);
RaycastHitInfo;
if(Physics.Raycast(光线原点、光线方向、外部命中信息、范围))
{
DrawLine(ray.origin、hitInfo.point、Color.red);
}
其他的
{
DrawLine(光线原点,光线方向*范围,颜色.绿色);
}
}
}
}
问题可能在第24行或第27行,但我仍然不知道它是如何出现的


编辑:我通过将光线方向设置为常量(-1,0,0)(全局左)来测试这一点,问题仍然存在,因此第24行中的光线声明可能存在问题。

我忘了将变换添加到else中的debug.drawline