Dynamic object creating

Hi,

I’ve got a script which I use for different objects, they all do the same thing, read the text file then add it to the list. But because of the line:

	Items RoomKey = new Items ();
	RoomKey.name = splittext [0];
	RoomKey.description =  splittext [1];
	RoomKey.type = (Items.Type)System.Enum.Parse (typeof(Items.Type), splittext [2]);;

I’ve been creating new scripts for each object, e.g. a flash light would have one that says ‘Items FlashLight = new Items();’

Is there a way of making it dynamic? So I can have just one script that all these objects use?

Thanks for any help

This is the full script:

public class RoomKey : MonoBehaviour {

	private Bag bag;
	
	string receivedtext;
	
	string[] splittext;
	
	public string filedirectory;

	void Awake()
	{
		
		bag = GameObject.FindGameObjectWithTag ("Player").GetComponent<Bag> ();
		
	}
	
	void OnTriggerStay (Collider other) {
		
		if (other.collider.tag == "Player") {
			
			if(Input.GetKeyDown(KeyCode.E))
			{
				
				ReadItemFile (filedirectory);
				
			}
			
		}
		
	}
	
	void ReadItemFile(string directory)
	{
		
		receivedtext = File.ReadAllText (directory);
		
		splittext = receivedtext.Split ("±"[0]);
		
		Items RoomKey = new Items ();
		RoomKey.name = splittext [0];
		RoomKey.description =  splittext [1];
		RoomKey.type = (Items.Type)System.Enum.Parse (typeof(Items.Type), splittext [2]);;
		
		bag.AddItems (RoomKey);
		
		Destroy (this.gameObject);
		
	}

}

I’m a little confused, in the script you attached there is nothing that appears to be hard coded for a ‘RoomKey’ other than the variable name and class name being RoomKey, renaming RoomKey to FlashLight does not change the function of the code at all, so why not just rename RoomKey to item and then it’s generic?