- Home /
Randomizer For a Polygon (RTS Unity)
Hi, i'm trying to create a randomizer for a polygon. The thing is, because this is not a normal asset, i'm struggling on how to make this work. For example because this uses earth as it's map asset, anytime I want to create something I need a longitude or latitude for the x and y positions.
Ex: OnlineMapsMarkerManager.CreateItem(longitudeAsX, latitudeAsY);
Now I'm trying to create a polygon using this code:
double lng, lat;
int n = 0;
OnlineMapsControlBase.instance.GetCoords(out lng, out lat);
markerPositions.Add(new Vector2((float)lng, (float)lat));
if(n == 0)
{
polygon = new OnlineMapsDrawingPoly(markerPositions, polyColor, 1, new Color(1, 1, 1,
0.5f));
polygon.n = m;
polygonDrawing.Add(polygon);
poly = OnlineMapsDrawingElementManager.AddItem(polygon);
poly.name = "Polygon";
}
n++;
polygonCenter = new Vector2((float)polygon.center.x, (float)polygon.center.y);
For now I'm using this code to make a randomizer
for (int i = 0; i < totalObs; i++)
{
foreach(Vector2 child in markerPositions)
{
x = UnityEngine.Random.Range(polygonCenter.x, child.x);
z = UnityEngine.Random.Range(polygonCenter.y, child.y);
}
OnlineMapsMarker marker = onlineMaps.Create(x, z, texture);
marker.scale = 0.2f;
marker.n = m;
marker.isObstacle = true;
}
But keep in mind by using this code, sometimes objects will spawn outside of the polygon. I wanted to use a collider for getting the boundaries, but because this asset always redraws any drawings into the mesh, the position of the polygon will always be Vector3(1, 1, 1) whenever it instantiates. Is there any way to workaround it??
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can I access the ^ key with qwertz keyboard-layout 2 Answers
Changes in the Custom Editor are not applied when restarting Unity 1 Answer
Monster AI patrol an idle 0 Answers