shapeIndex | 存储在 PhysicsShapeGroup2D 中的形状的索引。形状索引从零开始,形状组具有的形状数量由 shapeCount 指定。 |
radius | 要设置的形状半径值。 |
设置形状的半径。
using UnityEngine; using UnityEngine.Assertions;
public class Example : MonoBehaviour { void Start() { // Create a shape group. var shapeGroup = new PhysicsShapeGroup2D();
// Add a Circle to the shape group. var shapeIndex = shapeGroup.AddCircle ( center: Vector2.zero, radius: 0.5f );
// Fetch the Circle shape and validate the radius. var physicsShape = shapeGroup.GetShape(shapeIndex); Assert.AreApproximatelyEqual(0.5f, physicsShape.radius);
// Update the Circle radius. shapeGroup.SetShapeRadius(shapeIndex, 2f);
// Fetch the Circle shape and validate the radius. physicsShape = shapeGroup.GetShape(shapeIndex); Assert.AreApproximatelyEqual(2f, physicsShape.radius); } }