- Home /
Variable data type for two ints (x and y) in inspector
Is there a type of variable you can use that appears like a Vector2 in the inspector, but for ints only? So the inspector displays two values on the same line beside each other, but they're only ints, not floats.
I'd like to not have to convert the floats to ints at runtime, and it'd be handy to not just have two separate int values. Thanks!
Answer by phxvyper · Mar 24, 2017 at 12:13 AM
Make a type Vector2i
that looks something like:
struct Vector2i {
int x, y;
public Vector2i(int x, int y) { this.x = x; this.y = y; }
}
and mark it Serializable
:
[Serializable]
public Vector2i SomeIntVector;
That worked! I had to make some things public to be accessible, and it appeared in the inspector as a drop-down menu rather than horizontal fields like a regular Vector2, but that's okay. The exact code I ended up using:
[System.Serializable]
public struct Vector2i {
public int x, y;
public Vector2i(int x, int y) { this.x = x; this.y = y; }
}
public Vector2i SomeIntVector = new Vector2i(1,1);
Answer by Matt1000 · Mar 23, 2017 at 11:33 PM
If i were you I'd simply do a public Vector2 and only write ints in it. If you are talking for editor scripting there are other ways, but if not simply convert the floats to ints in the start (that should work)... since the inspector is set obviously before playing.
Other than that, no you can't, sorry.
Your answer
Follow this Question
Related Questions
Public variable not showing in Inspector(Solved) 1 Answer
Variable not changing on real-time problem 2 Answers
Script with variable number of variables ? 1 Answer
public string array controlled by an int in the inspector 1 Answer
Notes or Bubble Window for Variables in Inspector Giving Help? 3 Answers