unity's ray does not seem to detect objects
I want to connect the 20 points: if there is no obstacle between them, connect them; Obstacles do not connect
All nodes and obstacles have rigidbody and collider components
but some connections fail to cross obstacles.
< div class = "aw - list - img >
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class CGtest : MonoBehaviour
{
void Start()
{
for (int i = 1; i <= 19; i++)
{
for (int j = i + 1; j <= 20; j++)
{
Ray ray = new Ray(GameObject.Find("node" + i).transform.position, GameObject.Find("node" + j).transform.position);
RaycastHit hit;
Physics.Raycast(ray, out hit, 100);
if (hit.transform == null)
{
Debug.DrawLine(GameObject.Find("node" + i).transform.position, GameObject.Find("node" + j).transform.position, Color.red, 1000);
}
}
}
}
}
0 Answer
No answer yet
这家伙很懒,什么都没留下...