void AddSibling( GameObject go, bool before, bool keepWorldPosition )

book_4_sparkGenerated
code_blocksInput

Description

The AddSibling method allows you to add a GameObject as a sibling to the current GameObject. This method is useful when you want to organize your scene hierarchy by placing objects at the same level under a common parent.

Usage

To use the AddSibling method, you need to provide the following parameters:

  • go: The GameObject that you want to add as a sibling.
  • before: A Boolean value indicating whether the new sibling should be added before the current GameObject in the hierarchy. If true, the sibling is added before; if false, it is added after.
  • keepWorldPosition: A Boolean value that determines whether the world position of the GameObject should be maintained. If true, the world position is kept; otherwise, it may change based on the new hierarchy position.

Example

// Example of using AddSibling
GameObject currentGameObject = new GameObject();
GameObject newSibling = new GameObject();

// Add newSibling as a sibling to currentGameObject, placing it after and keeping its world position
currentGameObject.AddSibling(newSibling, false, true);