assigning several positions and call array of raycasts
I have a object that follows my cursor that i can build and place with a mouseclick. I can place it on a grid but i need to make restrictions where i cannot build. The places where i cant build are next to other objects and have edges of the object that are outside of the grid.
Ray ray = Camera.main.ScreenPointToRay(mousePos);
submarineZone[0].transform.position = new Vector3(mousePos.x, mousePos.y, mousePos.z);
I will call the ray on mousePos (which just is = with Input.mouseposition). I want to make an array of Raycasthits that will also be called but around the cursor. For my object that is 1x1 i need to have 8 raycasthits called that will check if other objects or restricted areas are next to it.
For example i need to change the Raycast Vector of submarineZone to this:
new Vector3(mousePos.x, mousePos.y+1, mousePos.z)
and i will check a block right on top of the cursor with the raycast.
However i could just edit all these raycast positions individually but that would eat up too much code and be un-efficient. How can i go about assigning the elements of the raycast arrays that will surround the cursor.
When i have bigger objects i will just divide each part of the object into 1x1 and have them call array raycasts around them so that wont be a problem.
So that i want to know is: Should i just hard-code each positions of the raycasts or can i do this in a way that doesnt need me to paste the same code over and over?
Thanks