Hi
I’m looking to create my own object that extends Vector3 that will allow me to have three x,y, and z parameters (string, string, and int).
I have no idea about how to go about this. I don’t need any functions on them, just be able to create an object with those three parameters.
- Vector3 is a struct not a class
- you may use struct instead of Vector3, and store them in List.(It’s more readable)
for example:
List< MyScore > allScore;
struct MyScore
{
Time time;
Time date;
int score;
}
If you want to be able to create a Vector3 from two strings and one int / float, you can create a function that creates one:
//C#
public static Vector3 CreateVector3(string aX, string aY, float aZ)
{
return new Vector3(float.Parse(aX),float.Parse(aY),aZ);
}
//UnityScript
public static function CreateVector3(aX : String, aY : String, aZ : float) : Vector3
{
return Vector3(float.Parse(aX),float.Parse(aY),aZ);
}
Note that those function don’t do any error checks. If one of the strings doesn’t contain a number that can be parsed into a float it will throw an exception.
This functions can be used like this:
//C#
Vector3 V = CreateVector3("12.5","10",5.0f);
//UnityScript
var V = CreateVector3("12.5","10",5.0);
If you want to store two strings and one int, like the others said, you have to create your own class / struct.
//C#
public struct MyDataType
{
public string s1;
public string s2;
public int number;
public MyDataType(string aS1, string aS2, int aNumber)
{
s1 = aS1;
s2 = aS2
number = aNumber;
}
}
Don’t ask me for the correct syntax in UnityScript since there is no direct way to create a struct. You have to derive a class from System.ValueType. Something like this:
public class MyDataType extends System.ValueType
{
var s1 : String;
var s2 : String;
var number : int;
}