How to create a new variable type?
Hello human beings!
In my game i want to record operations the player has made, but i want to record them as an array of a new type (something like Vector2) which gets an int and a float. How can one do that?
Thank you. Ethan
Just create a new class with an int and float as member variable. Add getters/setters for the variables and a default constructor and you're set.
How? I never needed such thing so i never learned about it? can you give an example?
Im not sure... somehting like this?
public struct OperationVector2 {
public GameObject operativeObject;
public float operationTime;
public OperationVector2(GameObject o, float t){
operativeObject = o;
operationTime = t;
}
}
A class would give you more options for expansion, like default constructors, operator overloading etc.
But a struct works fine, too. You can still convert it to a class later if needed.
C# is a real computer language, used for lots of things before Unity used it. If you Search for regular C# examples of arrays and making new types, you'll find many, many, many examples and explanations that all work the same way in Unity. Or you can read a regular C# book that explains it.
Asking here is nice for other people -- it gives them a chance to practice $$anonymous$$ching you -- but not really the best way for you to learn.
Your answer
Follow this Question
Related Questions
How can I define my own datatype?: `private EnemyCounter enemyCounter` 0 Answers
Vector2.MoveTowards Not Working 1 Answer
How to declare variables in class derived from other class variables in the same class? 0 Answers
Why i can't use veriable as a type? 0 Answers
How to make a global variable in Unity? 5 Answers