Click or drag to resize

StrixSyncFieldAttribute Class

An attribute for automatic variable synchronization.
Inheritance Hierarchy
SystemObject
  SystemAttribute
    SoftGear.Strix.Unity.RuntimeStrixSyncFieldAttribute

Namespace:  SoftGear.Strix.Unity.Runtime
Assembly:  StrixUnityRuntime (in StrixUnityRuntime.dll) Version: 1.5.0
Syntax
C#
public class StrixSyncFieldAttribute : Attribute

The StrixSyncFieldAttribute type exposes the following members.

Constructors
  NameDescription
Public methodStrixSyncFieldAttribute
Initializes a new instance of the StrixSyncFieldAttribute class
Top
Properties
  NameDescription
Public propertyFieldCode
Code used to identify the field.
Top
Remarks
Marking a field with this attribute will automatically detect value changes and synchronize it across all clients in the match room. Only changes made by the owner of the object get synchronized.
Examples
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;
using UnityEngine.UI;

public class StrixSyncFieldExample : StrixBehaviour
{
    [StrixSyncField]
    public int Health = 100;
    public Image HealthBar;

    private void OnMouseDown()
    {
        Rpc("Hit", Random.Range(3, 8));
    }

    [StrixRpc(ProcedureCode = 1)]
    public void Hit(int damage)
    {
        Health = Mathf.Max(0, Health - damage);
    }

    public void Update()
    {
        HealthBar.fillAmount = Health / 100f;
    }
}
See Also