A NullReferenceException is a C# runtime error caused by trying to use a reference that points to nothing. In Unity beginner projects, the most common cause is an unassigned Inspector reference, such as a missing GameManager, prefab, AudioSource or UI component. (course lab series, see source-csharp-unity-labs)
The first fix is not to rewrite the whole script. Read the Console line number, identify which reference is null, then check whether that field was assigned or found correctly.
Related: unity-inspector-references, getcomponent, serializefield, getcomponent-vs-inspector-references