GameObject Class
Constructor
GameObject(Vector2Int Position, string Name = "GameObject")
: Constructs a new instance of the GameObject class with the specified position and name.
Properties
_Name
: The name of the GameObject.transform
: The Transform component attached to the GameObject, representing its position, rotation, and scale.
Methods
AddComponent(Component component)
: Adds a new Component to the GameObject.AddComponent<T>()
: Adds a new instance of a specified Component type to the GameObject.GetComponent<T>()
: Retrieves the first Component of a specified type attached to the GameObject.
Example Usage
// Create a new GameObject
Vector2 position = new Vector2Int(0f, 0f);
string name = "MyObject";
GameObject myObject = new GameObject(position, name);
// Add a custom Component to the GameObject
myObject.AddComponent<Component>();
// Get a custom Component from the GameObject
myObject.GetComponent<Component>();
// Retrieve the Transform component
Transform transform = myObject.transfrom;