SyncedAxis Class

Alternative way of implementing InputSynchronizable.

Definition

Namespace: Alteruna
Assembly: Alteruna.Trinity (in Alteruna.Trinity.dll) Version: 1.3.4
C#
[SerializableAttribute]
public class SyncedAxis
Inheritance
Object    SyncedAxis

Example

We can setup a SyncedAxis in the inspector and register it in the Awake method.
Setup to sync the Horizontal axis and use its value.
C#
using Alteruna;
using UnityEngine;

[RequireComponent(typeof(InputSynchronizable))]
public class InputTest : MonoBehaviour
{
    public float Speed = 5;

    public SyncedAxis AxisX = new SyncedAxis("Horizontal");
    public SyncedAxis AxisY = new SyncedAxis("Vertical");

    private InputSynchronizable _input;

    void Awake()
    {
        if (_input == null)
            _input = GetComponent<InputSynchronizable>();

        AxisX.Register(_input);
        AxisY.Register(_input);
    }

    void FixedUpdate()
    {
        float scaledSpeed = Speed * Time.deltaTime;
        transform.Translate(
            scaledSpeed * AxisX.Value,
            scaledSpeed * AxisY.Value,
            0);
    }

    private void Reset()
    {
        if (_input == null)
            _input = GetComponent<InputSynchronizable>();
    }
}
Inspector setup of SyncedAxis

Properties

Axis Target axis.
Value Raw value of axis.

Methods

Deregister Deregister from IInput.
Register Register key to target IInput.
Register(IInput) Register key on target IInput.
Register(IInput, String) Register key to target IInput.

Operators

Fields

InputManager Connected IInput.

See Also