void Destroy()

robot_2Generated
code_blocksInput

Description

The Destroy method is used to mark a GameObject for destruction. The actual destruction of the object occurs at the start of the next frame, ensuring that any ongoing operations or references to the object can complete before it is removed from the scene.

Usage

Call this method on a GameObject instance when you want to remove it from the scene. This is useful for cleaning up objects that are no longer needed, such as temporary effects or objects that have completed their purpose.

Example

// Example of using the Destroy method
GameObject myObject = new GameObject();

// Perform operations with myObject

// Mark the object for destruction
myObject.Destroy();

// The object will be destroyed at the start of the next frame.