SourceSnippet
Come. Copy. Go. As simple as that!


thumbnail

Set-Get generator in unity

By Manas R. Makde
Posted: 22 March 2026
public event Action<int /* oldMyVar */, int /* newMyVar */> OnMyVarUpdated;

void SetMyVar(int newMyVar)
{
    // Return if trying to assign the same value
    if(newMyVar == myVar)
    {
        return;
    }


    // Store old point for broadcasting
    var oldMyVar = myVar;
    
    
    // Assign new point
    myVar = newMyVar;
    
    
    // Broadcast
    OnMyVarUpdated?.Invoke(oldMyVar, newMyVar);
}

int GetMyVar()
{
    return myVar;
}
unityc#