示例#1
0
    private void ExplodingSlice(Vector2f pos)
    {
        List <Slice2D> results = Slicer2D.ExplodingSliceAll(pos, sliceLayer);

        if (addForce == true)
        {
            foreach (Slice2D id in results)
            {
                foreach (GameObject gameObject in id.gameObjects)
                {
                    Rigidbody2D rigidBody2D = gameObject.GetComponent <Rigidbody2D> ();
                    if (rigidBody2D)
                    {
                        float sliceRotation = Vector2f.Atan2(pos, new Vector2f(gameObject.transform.position));
                        Rect  rect          = Polygon.CreateFromCollider(gameObject).GetBounds();
                        rigidBody2D.AddForceAtPosition(new Vector2(Mathf.Cos(sliceRotation) * addForceAmount / 10f, Mathf.Sin(sliceRotation) * addForceAmount / 10f), rect.center);
                    }
                }
            }
        }
    }