Hi,
I have a field in a class(named ngut) like these:
public string gsm;
Now the value of this field must be initialized when creating an instance of the respecting class.
I want to initialize gsm field with object’s name automatically. Thats it, after creating an instance, gsm should contain “X”(where X is the name of instanced object) string value. I set up constructor for this. But,
I do not want this,
ngut sample=new sample("sample");
I want to simply write,
ngut sample=new sample();
And gsm field automatically populate with “sample” value.
Can this be done anyhow?
I would recommend that you read up on static class members. They can easily deal with your problem as they are variables and arrays etc that exist at the same time in all objects that contain the class
I would personally just create a “static int count” variable. Increase count with one every time an object is created with the class and add it to the name like: “sample0”, “sample1” and “sample2” etc.
Just note that you cannot decrease count if you randomly destroy the scene objects because that will cause duplicate names to appear. Just increase and add… ints are pretty big so I doubt that you will reach the limit