Hi,
First of all, it’s great to see that you are trying to implement your own ideas. 
NullReferenceException is one of the most common errors a programmer gets. It means that a reference (“link”) to an instance is missing. If you exposed a field in the Inspector, make sure that it’s not empty. When you get this error, pause the game and check the fields.
If all fields in your Inspector contain references, double click on the error message to learn to which line in your code it refers. There is very likely a variable that is supposed to contain a reference to an object. It’s not a number or a char because those are value types.
In the Start method of your MainGame.cs, there is a for loop without any code block. If it does not have any purpose, remove it.
At the moment, I don’t know what could be causing the out of memory issue, so I’d recommend to fix the problems in Unity first before you try to fix the WebGL build.
See also:
- GameDev.tv Community: WebGL Debugging