Hi everyone,
I have been trying to understand this issue for a while and cannot get around it. All of the following is happening inside the Update() method. I made a Raycast array and Raycasthit array for my enemies to be triggered by the player (perhaps I can sweep a single Raycast and that would be more accurate and efficient, but that’s not the point here, I want to make it work my way now). When any Raycast is triggered, the foreach loop is entered to check what each single ray actually hit. For some unknown reason, only two raycasts per frame are actually being used inside the foreach loop, instead of the full set of five rays. Does anyone understand why this should happen?
RaycastHit[] colliderColpito = new RaycastHit[5]; //https://answers.unity.com/questions/897639/raycast-conundrum.html
bool[] ray = new bool[5];
ray[0] = Physics.Raycast(rifTransform.position + transform.up, exNorm0, out colliderColpito[0], distanzaAvvistamento); //genera raycast e applica filtro layer per ignorare triggers e altri colliders
ray[1] = Physics.Raycast(rifTransform.position + transform.up, exNorm1, out colliderColpito[1], distanzaAvvistamento);
ray[2] = Physics.Raycast(rifTransform.position + transform.up, exNorm2, out colliderColpito[2], distanzaAvvistamento);
ray[3] = Physics.Raycast(rifTransform.position + transform.up, exNorm3, out colliderColpito[3], distanzaAvvistamento);
ray[4] = Physics.Raycast(rifTransform.position + transform.up, exNorm4, out colliderColpito[4], distanzaAvvistamento);
//Debug.Log("a" + ray[0] + "b" + ray[1] + "c" + ray[2] + "d" + ray[3] + "e" + ray[4]);
foreach (bool rayelement in ray)
{
Debug.Log(System.Array.IndexOf(ray, rayelement)); //This shows that only a couple of elements of the ray per frame are actually being iterated
}
Thanks in advance!