Component Class
Description
The Component class is an abstract base class for creating components that can be attached to GameObjects.
Properties
gameObject: GameObject
: Reference to the parent GameObject that the component is attached to.
Methods
Start(): void
: Called when the component is started or initialized.Update(): void
: Called every frame to update the component's logic.GetGameObject(): GameObject
: Retrieves the parent GameObject of the component.
Usage
To create a custom component, you can inherit from the Component class and override its methods as needed. Here's an example:
using OneratConsoleEngine;
public class MyComponent : Component
{
public override void Start()
{
// Perform initialization logic here
}
public override void Update()
{
// Perform update logic here
}
}
To attach the component to a GameObject, you can use the AddComponent
method:
// Get the attached component on the GameObject
gameObject.AddComponent<Component>();
// Create a new GameObject
GameObject gameObject = new GameObject();
// Attach the component to the GameObject
gameObject.AddComponentTo get the attached component on a GameObject, you can use the GetComponent
method to access the Component:
// Get the attached component on the GameObject
gameObject.GetComponent<Component>();
// Get the attached component on the GameObject
gameObject.GetComponent