title: Unity game engine: get reference to dynamically added script
body: <p>I have a base class called Weapon and several derived classes e.g. Weapon_Rifle, Weapon_Pistol etc.</p>
  
  <p>In another class I need to reference whatever derived class of Weapon exists on the GameObject in question. In pseduocode what I'm trying to do is this:</p>
  
  <pre><code>public class OtherClass : MonoBehaviour
  {
  
       public string weaponType;
       public SCRIPT_I_WANT_TO_REFERENCE;
  
       void Awake(){
            if(weaponType =="Rifle"){
                 SCRIPT_I_WANT_TO_REFERENCE = GetComponent&lt;Weapon_Rifle&gt;();
            } else {
                SCRIPT_I_WANT_TO_REFERENCE = GetComponent&lt;Weapon_Pistol&gt;(); // etc etc
            }
       }
  
       void DoStuff(){
            SCRIPT_I_WANT_TO_REFERENCE.ShootWeapon();
       }
  }
  </code></pre>
  
  <p>Trouble is of course I can't use a dummy type like Object for the SCRIPT_I_WANT_TO_REFERENCE as the compiler complains where I try to access methods of that script like ShootWeapon().</p>
  
  <p>Any way this can be done?</p>
  
  <p>Many thanks.</p>