Page 1 of 1

Wie stelle ich sicher, dass dieser Teil des Unity3D C# -Codes nicht ausgeführt wird, wenn der Spieler aufhört zu spielen

Posted: 14 Apr 2025, 17:31
by Anonymous
Das Problem ist, wenn der Spieler aufhört, das Spiel zu spielen, wird der Code im Onvalidat ausgeführt, und ich möchte vom Code aus dem Code vermeiden, den Code auszuführen, wenn Sie das Spielen nicht mehr ausführen. Ich möchte, dass der Code im Editor -Modus funktioniert, aber nicht beim Beenden des Spiels. < /p>

Code: Select all

private void OnValidate()
{
if (line == null)
line = GetComponent();

if (!Mathf.Approximately(changeBothRadius, previousChangeBothRadius))
{
xradius = changeBothRadius;
yradius = changeBothRadius;
previousChangeBothRadius = changeBothRadius;
}

ConfigureLineRenderer();
CreatePoints();

if (Application.isPlaying || UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
return;

if (numOfObjects != previousNumOfObjects)
{
previousNumOfObjects = numOfObjects;

UnityEditor.EditorApplication.delayCall += () =>
{
ClearObjects();
EnsureObjects();
};
}

UpdateDebugText();
}