'how can I instantiate a prefab modified with variables pulled from another script?

To preface, I'm very new to Unity and programming in general, let alone C#. So I'd appreciate extra explanations surrounding the reasoning for the code you choose to answer my question. I've also scoured the internet for an answer to my question, and although many were close, none answered it perfectly.

WHAT I WANT

I'm creating a State.io type game, following this tutorial. I'm trying to randomly spawn the same prefab called "Node", at random positions (Check), without overlapping (Check), but with different "factions". The three possible factions are PLAYER, DEFAULT and ENEMY. Each has its own faction name, material colour and type (BIG, MEDIUM, SMALL).

WHAT I'VE DONE

I have a Node script linked to each prefab ("Node") summed below:

public enum Faction
{
    DEFAULT,
    PLAYER,
    ENEMY
}
public class Node : MonoBehaviour
{
    public Material[] materials;
    public enum NodeType
    {
        BIG_CELL,
        MEDIUM_CELL,
        SMALL_CELL
    }
    public Faction faction;
    public NodeType type;

    public GameObject NodePrefab;
    public void PlayerConverter()
    {
        GameObject PlayerNode = unitPrefab;
        PlayerNode.GetComponent<Spawner>().SetPlayer(Faction.PLAYER, materials[2]);
        //faction = Faction.PLAYER;
        //type = NodeType.BIG_CELL;
    }
}

The Materials matrix on each prefab is 3 and defined properly.

I also have a Spawner script linked to an empty game object, summed here:

public class Spawner : MonoBehaviour
{
    public GameObject originPrefab;
    public Faction faction;
    //public NodeType type; //For some reason this doesn't work:error CS0246: The type or namespace name 'NodeType' could not be found (are you missing a using directive or an assembly reference?) - But that's not important right now

    public void SetPlayer(Faction _faction, Material mat)
    {
        GameObject PlayerNode;
        PlayerNode.GetComponent<Node>().Faction = _faction;
        PlayerNode.GetComponent<Node>().Material = mat;
        //faction = originPrefab.GetComponent<Node>().Faction(PLAYER)
        //GameObject PlayerNode = originPrefab.GetComponent<Node>().Faction(PLAYER);
        //PlayerNode.GetComponent<Node>().faction("PLAYER");
    }

    public void Start()
    {Instantiate(PlayerNode, new Vector3(screenX, screenY, 0), Quaternion.identity);}
}

I did remove some variables from this code segment here because it's irrelevant to the question. I want when the game to start to instantiate the PlayerNode which at that point would be defined as the originalPrefab but with modifications to faction, material and type. Then I'd repeat the same process for the other DEFAULT and ENEMY.

QUESTION

My question is, how can I use the same prefab to construct different factions. The only way I've able to do this is to just create different prefabs for each faction, but I'd rather this process be automated. I've spent the last week determined to fix this, but couldn't. Any ideas, resources, code snippets with explanation is so very much appreciated, thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source