How to get variable from another unknown script ?

Hi, I’m beginner on Unity and I didn’t find an answer to my question on the web, so I ask it here (and sorry if my English is not perfect, I’m French). So, I created a quest system that use many scripts with the same variables names, but with different names which allows me to identify them (Example : quest_1_1_201, the first number is the ID of the quest, the second is the number of steps to finish it… but the script variables names are the same than quest_2_1_101 for example), and I want to get their variables without knowing their names, just with a string that display the current quest. For example, if I want to know if the currentStep of the quest is 3, I tried this :

public string currentQuestID;

void Update () {
	currentQuestID = GetComponent<RPGQuestManager>().currentQuestID;

	//in the quest manager script are listed all the quest that are accepted by the player, but only one can be selected

	if (GetComponent(currentQuestID)) {
		if (GetComponent(currentQuestID).currentStep == 3) {
			Debug.Log ("It works !");
		}
	}
}

But it doesn’t work, I don’t know how to access this variable, I spent hours on this forum and I tried lot of methods but none has worked, or it was just to hard for me.

Anyone could help me please ?

I think you have the right idea, and the wrong implementation. The way I’d suggest structuring would be to have your RPGQuestManager contain an array of Quests, which contains references to all quest scripts.

This means each quests should implement an interface that provides functions to access the data you need like getting the current step. Coding to an interface is explained well here.

On Awake, each quest should register itself with the RPGQuestManager. This means that RPGQuestManager should have a RegisterQuest function which takes a Quest as an argument and places it in the array of Quests.

Finally, RPGQuestManager should have a variable called CurrentQuestIndex which is just an int and which represents the index of the current quest. You should then be able to access the current quest via that index.

Hope this helps!