Hi,
So I made a Random Encounter Generator that Rolls dice to determine how many and what types of enemies your character will be fighting. Each different type of enemy has a specific script. It creates a GameObject and attaches the specific enemyType script to it and your player GameObjects starts fighting the enemy GameObjects, yada yada.
All the stat variables are stored in their specific scripts. So I need to figure out how to get those variables in runtime without knowing a specific script name because it could be any enemyScript.
The PlayerScript Targets an enemy GameObject like this:
public void GetClosestTarget(){
GameObject[] objectsWithTag;
objectsWithTag = GameObject.FindGameObjectsWithTag ("Enemy");
foreach (GameObject go in objectsWithTag) {
float distance = Vector2.Distance(go.transform.position, transform.position);
if(distance < targetDistance){
currentTarget = go;
}
}
}
So my Players current Target is stored as a Gameobject in the currentTarget variable. I need to figure out what script is attached to that currentTarget GameObject. So I can access that enemies stats.
currentTarget.GetComponent<???>();
Basically I need to find out how to make a function that figures out what ??? is.