void CreateAsteroid() { GameObject newGameObject = new GameObject(); newGameObject.name = "Aseteroid"; float ratio = (float)Screen.width / Screen.height; newGameObject.transform.position = new Vector2(Random.Range(-Camera.main.orthographicSize * ratio, Camera.main.orthographicSize * ratio), Camera.main.orthographicSize); Polygon2D polygon = new Polygon2D(); float rot = 0; while (rot < 360) { float dist = Random.Range(50, 100); polygon.AddPoint(Mathf.Cos(Mathf.Deg2Rad * rot) * dist / 100f, Mathf.Sin(Mathf.Deg2Rad * rot) * dist / 100f); rot += Random.Range(10, 45); } polygon.CreateCollider(newGameObject).isTrigger = true; //newGameObject.AddComponent<SliceroidsKeepInScreen>(); SliceroidsColliderLineRenderer2D lineRenderer = newGameObject.AddComponent <SliceroidsColliderLineRenderer2D>(); lineRenderer.color = new Color(56f / 255, 1, 239f / 255, 1f); newGameObject.AddComponent <Rigidbody2D>().AddForce(Vector2D.RotToVec(Vector2D.Atan2(new Vector2D(Vector2.zero), new Vector2D(newGameObject.transform.position))).vector * 100); newGameObject.AddComponent <Slicer2D>().textureType = Slicer2D.TextureType.None; }
private void CreatePolygon(Polygon2D newPolygon) { GameObject newGameObject = new GameObject(); newGameObject.transform.parent = transform; newGameObject.AddComponent <Rigidbody2D> (); newGameObject.AddComponent <ColliderLineRenderer2D> ().color = Color.black; Slicer2D smartSlicer = newGameObject.AddComponent <Slicer2D> (); smartSlicer.textureType = Slicer2D.TextureType.Mesh2D; smartSlicer.material = material; newPolygon.CreateCollider(newGameObject); newPolygon.CreateMesh(newGameObject, new Vector2(1, 1), Vector2.zero, PolygonTriangulator2D.Triangulation.Advanced); }