ModManager.Spawn C# (CSharp) Method

Spawn() public method

public Spawn ( string Name, Vector3 Position ) : GameObject
Name string
Position Vector3
return GameObject
    public GameObject Spawn(string Name, Vector3 Position)
    {
        GameObject ClonedObject = new GameObject();
        ClonedObject.transform.position = Position;

        Moddable TheModdable = null;

        try
        {
            Type TheType = null;
            Mod TheMod = null;

            foreach (KeyValuePair<string, Mod> Entry in Mods)
            {
                if (Entry.Value.Moddables.TryGetValue(Name, out TheType))
                {
                    TheMod = Entry.Value;

                    break;
                }
            }

            if(TheType != null)
            {
                TheModdable = (Moddable)ClonedObject.AddComponent(TheType);
                TheModdable.TheMod = TheMod;
            }
        }
        catch(Exception e)
        {
            Debug.Log("Unable to start mod '" + Name + "': " + e.Message);

            return null;
        }

        return ClonedObject;
    }