I have attached pollygon collider 2d on this gameObject.
![alt text][1]
This gameObject is parent of another gameObject (just small circle).
**I want that small circle to randomly spawn somwhere on pollygon collider.**
I tried something like this:
private void GetBounds()
{
polygonCollider = transform.parent.gameObject.GetComponent();
bounds = polygonCollider.bounds;
}
public void TargetSetPosition()
{
x = Random.Range(bounds.min.x, bounds.max.x);
y = Random.Range(bounds.min.y, bounds.max.y);
transform.localPosition = new Vector2(x, y);
}
private void Start()
{
GetBounds();
TargetSetPosition();
}
**This script is attached to that small circle. In 80% cases is good result but sometimes it get weird something like this:**
![alt text][2]
Can someone help me please, becouse i tried almost everything
[1]: /storage/temp/176661-polygon.jpg
[2]: /storage/temp/176689-screenshot-2.jpg
↧