- Home /
Stored data and GameObject
Hello everybody,
I'm working with Unity for a couple of months and I am actually facing a "problem". It's more a question than a problem but I would like to know how works the management of data.
Here is my point with an example: I would like to create an instance of the class Cat.
Cat is a simple C# class with functions and attributes.
public class Cat : ISerializable{
private string name;
public string Name{
get{return name;}
set{name = value;}
}
private int age;
public int Age{
get{return age;}
set{age = value;}
}
...
public Cat(string name, int age){
this.name = name;
this.age = age;
}
...
}
I instantiate my new cat Billybob with a little editor by giving the name and the age of the newborn.
Until there, nothing is special. My question is : Am i allowed to get my Billybob information without putting the instance Billybob in a MonoBehaviour attached to a GameObject in my Scene?
Or am I forced to made my Cat class inherit from MonoBehaviour and to create a GameObject Billybob and do an AddComponent("Cat") stuff?
The simple question is : do I need GameObject to access data that i've created :)?
Thanks for any help.
Iwa
Answer by whydoidoit · May 02, 2013 at 02:43 PM
No you don't. You just need to make the instances of it somewhere. That could be inside a MonoBehaviour or a static class.
Thanks for your answer. I still wonder how do i get access to my information of Billybob if it is a static class? And what will my static class will look like?
public static class SomeClass
{
public static List<Cat> cats = new List<Cat>();
}
Then to access it:
SomeClass.cats.Add(new Cat("Billybob", 2));
Your answer
Follow this Question
Related Questions
Arrays vs. XML or SQLite: Fastest data storage/retrieval using JavScript/UnityScript? 0 Answers
android serialization weird path issue " IsolatedStorageException ", javascript 0 Answers
Scene management trick? 0 Answers
What are good ways to store a simple set of data/variables on an object 2 Answers
How to structure my project so that I can save/load information? 0 Answers