Non-static commands

Adding non-static commands

Non-static methods or properties require an instance in order to be executed. Instances are found automatically behind the scenes, which means there is no additional setup required on your part.

public class Player : MonoBehaviour
{
    private float currentHealth;

    [Command]
    public int Health
    {
        get => currentHealth;
        set => currentHealth = value;
    }
}

Typing health 10 will execute on all instances of Player found in the scene.

Additionally, a name can be specified at the end of the input prefixed with @. Doing so will execute the command only on instances with the specified name.

The name is always specified at the end of the last required parameter. So for example, if we want to just print the value of a property instead of setting it, we could type: health @MyPlayer.

Last updated