title: Adding data to a list from another script in unity c#
body: <p>First time using Stackoverflow, thanks very much in advance for any help or examples. The aim is to fill a list called 'playerList' with 'PlayerTank' objects from another script.</p>
  
  <p>I've created a list called 'playerList' in a script called 'PlayerList' </p>
  
  <p>In this I also created the subclass'PlayerTank' with a constructor. The aim is to fill 'playerList' with 'PlayerTank' objects. Heres the code.</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  
  public class PlayerList : MonoBehaviour {
  
      public List&lt;PlayerTank&gt; playerList;
  
      public class PlayerTank { // Here is my class for PlayerTank
  
          public int playerNumber;
          public int playerPadNumber;
          public string playerName;
          public string playerColour;
  
  
          // This is a constructor to make an instance of my class. 
  
          public PlayerTank (int newPlayerNumber, int newPlayerPadNumber, string newPlayerName, string newPlayerColour) 
          {
              playerNumber = newPlayerNumber;
              playerPadNumber = newPlayerPadNumber;
              playerName = newPlayerName;
              playerColour = newPlayerColour;
          }
  
  
      }
  
  
  void Start () {
  
          playerList = new List&lt;PlayerTank&gt;();
  
      }
  
      }
  }
  </code></pre>
  
  <p>The above works fine and dandy.</p>
  
  <p>However, In a completely separate script called 'Test' I am trying to now add playerTank objects into this list. </p>
  
  <p>None of the below gets even close to working but I'm including it so it might give some insight as to my thought process!</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  
  
  public class Test : MonoBehaviour {
  
      public GameObject playerData;
      PlayerList playerList;
      PlayerTank playerTank;
  
  
  
      // Use this for initialization
      void Start () {
          playerList = playerData.GetComponent&lt;PlayerList&gt; ();
          playerTank = PlayerList.PlayerTank;
  
          playerList.playerList.Add (new playerTank.playerTank(1,2,"a player name", "black")); 
      }
  
  }
  </code></pre>
  
  <p>Of course none of the above works! Thanks very much for looking!</p>