title: Use of addComponent instead of new keyword in unity
body: <p>I have an interface which all my monsters should implement.</p>
  
  <pre><code>namespace Assets.Scripts
  {
      interface IMonster
      {
          void setSpeed(float s);
          float getSpeed();
          void SetMonsterPosition(Vector2 pos);
          Vector2 GetMonsterPosition();
          void DestroyMonster();
          void MoveMonster();
      }
  }
  </code></pre>
  
  <p>Then I have a concrete monster class (I will add more):</p>
  
  <pre><code>public class Monster2 : MonoBehaviour, IMonster
  {
  
      public Monster2()
      {
          speed = Random.Range(0.05f, 0.15f);
          monster = (GameObject)Instantiate(Resources.Load("Monster2"));
          float height = Random.Range(0, Screen.height);
          Vector2 MonsterStartingPosition = new Vector2(Screen.width, height);
          MonsterStartingPosition = Camera.main.ScreenToWorldPoint(MonsterStartingPosition);
          monster.transform.position = MonsterStartingPosition;
      }
  
      void Start()
      {
  
      }
  
      // Update is called once per frame
      void Update()
      {
  
      }
  
  }
  </code></pre>
  
  <p>And a factory class that will produce my monsters:</p>
  
  <pre><code>class MonsterFactory : MonoBehaviour
      {
  
          public static IMonster getMonster()
          {                
              return new Monster2();                
          }
      }
  </code></pre>
  
  <p>This works but I read that I should not use new and I should use AddComponent. So I tried something like:</p>
  
  <pre><code>class MonsterFactory : MonoBehaviour
      {
          public static GameObject mymonster;            //@first
          public static IMonster getMonster()
          {   
              return mymonster.AddComponent&lt;Monster2&gt;(); //@second                
          }
      }
  </code></pre>
  
  <p>The problem is that now when I am trying to run the game there is a an error <code>NullReferenceException: Object reference not set to an instance of an object</code></p>
  
  <pre><code>IMonster monster = MonsterFactory.getMonster();
  </code></pre>