- Home /
The question is answered, right answer was accepted
Placing Multiple GO's In Selected Area
I am making a level editor for my game and i am currently trying to make a tool that when you hold down the mouse it places multiple gameobjects in the area selected filling it up. I'm not to sure how to go about this and have currently got the selection part working which allows me to call me function with the two vector3's. I'm not sure i explained this well so heres a picture of what i mean:
My current function is structured like this:
void PlaceSelectionOfBlocks(Vector3 _initialPos, Vector3 _endPos)
{
}
And i am using createBlock(Vector3 position) to create my block. Also everything is aligned to a grid. Thanks.
Answer by c97 · Sep 23, 2017 at 03:01 AM
I haven't tested this, but something like this should work. Substitute your variables in for the parts with brackets.
for (float x = Mathf.min(_initialPos.x, _endPos.x); x < Mathf.max(_initialPos.x, _endPos.x) - Mathf.Epsilon; x += [block length])
{
for (float z = Mathf.min(_initialPos.z, _endPos.z); z < Mathf.max(_initialPos.z, _endPos.z) - Mathf.Epsilon; z += [block width])
{
createBlock(new Vector3(x, [some y position], z));
}
}
You probably need the Epsilon part because float addition isn't exact.
Thanks for the help the now it only works when the end point is towards the top right of the start point/when it is positive.
I edited it so that for both x and z, it starts with the point with the smaller coordinate and ends at the point with the larger coordinate.
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do i Achieve mesh Extrusion? 2 Answers
How to Instantiate a GameObject from a ScriptableObject piece of script? 0 Answers
Can I make a collider ignore only one other collider? 0 Answers