Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetShape(int)

Gets the PhysicsShape2D stored at the specified shapeIndex.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.Physics2DModule
public PhysicsShape2D GetShape(int shapeIndex)

Parameters

shapeIndex

The index of the shape stored the PhysicsShapeGroup2D. The shape index is zero-based with the shape group having a quantity of shapes specified by shapeCount.

Returns

Type

Description

PhysicsShape2DReturns the shape stored at the specified
shapeIndex
.

Remarks

NOTE: Because the PhysicsShape2D is a struct, this is a copy of the shape therefore changing the shape afterwards will not change the PhysicsShapeGroup2D.

Examples

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 circleShapeIndex = shapeGroup.AddCircle ( center: new Vector2(-2f, 3f), radius: 1f ); // Add a Capsule to the shape group. var capsuleShapeIndex = shapeGroup.AddCapsule ( vertex0: Vector2.down, vertex1: Vector2.up, radius: 0.5f ); // Validate the contents. Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(circleShapeIndex).shapeType); Assert.AreEqual(PhysicsShapeType2D.Capsule, shapeGroup.GetShape(capsuleShapeIndex).shapeType); }}