Hi All
I am trying to write my first application with Unity and while enjoying it I have hit a bit of a brick wall with class creation.
I have three scripts:
- the first reads a csv file into an array and calls the class constructor
- the second defines the class and has the class constructor
- the third searches the classes.
The third script is attached to a different object to the first two.
The probelm I am having is creating a class that has the name from the array and that can be called from another object.
Roughly scripts look like(the actual scripts are very long as the class has a lot of details):
script 1
array [name, detail, detail2] with many rows
for
personName = array[0];
personDetails = array[1];
personDetails2 = array[2];
script2.createPerson(personName, personDetails, personDetails2);
script2
class person
{
public var detail : string =“text”;
public var detail2 : int = 2;
}
static function createPerson (name, detail, detail2)
{
???
}
script3
if (name.detail == something)
{
do something;
}
So the question is how do I use createPerson to create a public object I can see from anywhere which looks like
person.detail
person.detail2
I have tried
CreatePerson (name, detail, detail2){
name= new createPerson();
name.birthplace = detail;
name.age = detail2;
}
But I cant then see “Luke.birthplace”.
Any advice on either how to achieve this or a better way to do it would be really appreciated. I can post full functions if it helps but they are quite long.