Skip to content

Scripting API

Victor edited this page Jan 17, 2023 · 3 revisions

C# API

Components

Components are structs that can only contain variables.

Example:

[Component]
public struct PlayerComp 
{
    public float Speed;
    public bool Grounded;
}

Behaviour

Behaviours is the base class for a scriptable system.

Methods

Called at the start of the game

void Awake(){}

Called at the after Awake

void Init(){}

Called every frame

void Update(){}

Example:

[Component]
public struct PingPongComp
{
    public float speed;
    public float turnTime;
    public float turnTimer;
    public int direction;
}
class MovePingpong : Behaviour
{
    void Update()
    {
        ref Transform3D t3d = ref GetComponent<Transform3D>();
        ref PingPongComp ppc = ref GetComponent<PingPongComp>();

        ppc.turnTimer += Time.DeltaTime();

        Vector3 forward = Math.CalculateForward(ref t3d);

        if(ppc.turnTimer >= ppc.turnTime)
        {
            ppc.turnTimer = 0.0f;

            ppc.direction *= -1;
        }

        t3d.LocalPosition += forward * ppc.speed * Time.DeltaTime() * ppc.direction;
    }
}

Clone this wiki locally