Onerat Games
  • Home
  • Games
    • Elden: Path of the Forgotten
    • Outback
    • Itch.io
  • Learn
    • Onerat's C# Console Engine >
      • Getting Started
      • Scripting API >
        • GameObject
        • Rigidbody
        • Transfrom
        • Component
        • Input
        • Rect
        • Screen
        • Vector2
        • Console Engine Math
      • Lessions >
        • Lesson 1: Snake
        • Lesson 2: Particle Simulation
        • Lesson 3: Tetris
      • Donate
      • Download
  • Asset Store
Component Class Documentation

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.AddComponent();

To 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();
Powered by Create your own unique website with customizable templates.
  • Home
  • Games
    • Elden: Path of the Forgotten
    • Outback
    • Itch.io
  • Learn
    • Onerat's C# Console Engine >
      • Getting Started
      • Scripting API >
        • GameObject
        • Rigidbody
        • Transfrom
        • Component
        • Input
        • Rect
        • Screen
        • Vector2
        • Console Engine Math
      • Lessions >
        • Lesson 1: Snake
        • Lesson 2: Particle Simulation
        • Lesson 3: Tetris
      • Donate
      • Download
  • Asset Store