Guidelines to create a new game object or data type.

Hello!

The game I´m working on right know requires the feature to let the player create a new “country”. This isen´t a visible object, it just exists in code and strings. So lets say I have a script called “canada.cs” with all its variables and such.
The player press a button that triggers something like this:

myCountry = new canada();

Of course this is just some psuedo code, I really don´t know if this is the right way to do this. Every country have different properties and variables too, so I can´t just do canada = new country(); either.

Well, I guess my question is a bit unclear, but if every country have a script and when that country gets created, I can use the that scripts properties to print something like “You discovered Canada”.

I would really appreciate some help here :wink: If something is unclear, just ask me!

Regards!

Here is an example of a country class. The bottom section would most likely be a monobehaviour script that would be attached to whatever object that you want to handle the country creation in.

public Class Country
{
 public string Name;

public Country(String name)
{
   this.Name = name;
}

}


public Class CountryCreator: MonoBehaviour
{
 
void Start()
{
  Country canada = new Country("Canada");
     Debug.Log("You discovered "+ canada.Name);  


Country MickyMouse = new Country("Super Duper Land");
     Debug.Log("You discovered "+ MickyMouse.Name);  


}

}

Hi man, thanks for helping me out!

I´m so sorry, I forgot to mention that I script with C#. This looks C# though, just wanted to make sure it really is!

You can tell quite easily if its JS/C#

C# functions are defined like:
void Update()…

JS
function Update()…