コード例 #1
0
        protected virtual void Ray(float maxDistance, List <GameObject> objects, Vector3 direction)
        {
            closestObjectDistance = null;
            closestObject         = null;
            Raycast ray = new Raycast(Owner.GlobalPosition, direction, maxDistance);

            foreach (GameObject go in objects)
            {
                if (go == Owner)
                {
                    continue;
                }
                Collider col = go.GetComponent <Collider>();
                if (go.IsVisible && go.Name != "Level")
                {
                    float?distance = (col != null ? ray.Intersect(col.bound) : ray.Intersect(go.Bound));
                    if (distance != null)
                    {
                        if (closestObjectDistance == null || distance < closestObjectDistance)
                        {
                            closestObjectDistance = distance;
                            closestObject         = go;
                        }
                    }
                }
            }
        }