Review generated patrol motor

from MonoBehaviour lifecycle
Unity 6.6 advanced 6 min 4 issues to find

Review this generated patrol motor against the stated lifecycle contract.

While active, respond to PatrolClock.FixedTick and push only this Rigidbody; recover after re-enable, fail clearly on invalid setup, avoid per-tick logs, and keep Inspector configuration private.

csharp
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public sealed class PatrolMotor : MonoBehaviour
{
    public float acceleration = 6f;
    private Rigidbody body;

    private void Start()
    {
        body = GetComponent<Rigidbody>();
        PatrolClock.FixedTick += ApplyThrust;
    }

    private void OnDisable()
    {
        PatrolClock.FixedTick -= ApplyThrust;
    }

    private void ApplyThrust()
    {
        body.AddForce(transform.forward * acceleration);
        Debug.Log("thrust");
    }
}

generated code is illustrative, not from any one model

Open in playground
Report an error