cant iterate through after boxcast or spherecast problem need help please
Hello, I have tried a lot of stuff and I am unsure why my simple script will not work.
The player spawns in an empty scene and the world generates around the player. I am trying to use boxcast or spherecast to get the objects closest to the player and switch the renderer oon. But alas it collects the objects into an array but after woods its as tho it misses my iteration altogether.
I have tried it several ways and tried my own custom timed iteration but its as tho it forgets how to do an iteration because I'm using an array maybe? Didn't think it would matter as you can iterate through array ok in other cases.
Not sure why it wont work. Am stumped, please help.
// Update is called once per frame
void FixedUpdate()
{
if (tickTimer < tickTimerMax + 10f)
{
tickTimer += 0.1f;
}
if (tickTimer >= tickTimerMax)
{
// renderer can be enabled and disabled from start.
RaycastHit[] he = Physics.BoxCastAll(transform.position,
new Vector3(20, 20, 20), new Vector3(0, 0, 0),
Quaternion.identity, 20f, everythingMask);
hits = he;
for (int k = 0; k < hits.Length; k++)
{
hits[k].transform.GetComponent<Renderer>().enabled = true;
}
}
}
Answer by Kastenessen · Feb 14, 2016 at 08:16 PM
Solved it. I needed to add the range into the boxcastall, and a few other things that dont know why it causes it not to work but all good. Is working now, sorry to bother.