Unidad donde hay dos rayos,
- A la radiación no penetra el objeto
Physics.Raycast
, como se muestra a continuación, los rayos son bloqueados por el cuerpo de la cápsula.
- A la radiación puede penetrar el objeto
Physics.RaycastAll
, el método puede detectar todos los rayos de colisión
Ambos métodos eran para escribir un ejemplo de ello.
Physics.Raycast
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayTest : MonoBehaviour
{
// Start is called before the first frame update
private RaycastHit raytest;
private Ray a;
void Start()
{
}
private void Update()
{
a = new Ray(transform.position,transform.forward);
int b = LayerMask.GetMask("test","test1");
int c = (1 << 9) | (1 << 10);
Debug.Log("b::::::::"+b+",,,,,c::::::"+c);
if(Physics.Raycast(a,out raytest,200,b)){
Debug.Log(raytest.point);
Debug.Log(raytest.transform.name);
}
Debug.DrawLine(transform.position,raytest.point,Color.magenta);
}
}
Physics.RaycastAll
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayTestAll : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Ray ray = new Ray(transform.position,transform.forward);
RaycastHit[] rays = Physics.RaycastAll(ray, 100);
foreach (var VARIABLE in rays)
{
Debug.Log(VARIABLE.transform.name);
}
Debug.DrawLine(transform.position,transform.forward*100,Color.red);
}
}