It doesn't infer what is in a variable by the type of the object stored in the variable, but rather, by the type declared for the variable (exceptions made for those types that inherit from UnityEngine.Object). Well, you're going to run into a big issue in that unity serializes in a staticly typed manner. Gets the signed angle in degrees between from and to. Reflects a vector off the vector defined by a normal. ![]() The result is always rotated 90-degrees in a counter-clockwise direction for a 2D coordinate system where the positive Y axis goes up. In a statically typed language, the compiler expects you to tell it what to do.īut you're also talking about in the inspector. Returns the 2D vector perpendicular to this 2D vector. Or are you saying add the number 0 to the number 1? Should this be "10" or should it be 1? Are you saying append the string "0" to the string "1". It's doing so because why the heck are you treating some value like something it's not!? How does it know what you expect the conversion to be! but a staticly typed language isn't throwing an exception abitrarily. One might argue that free casting in Lua is better because you avoid exceptions. where as C# is staticly typed and requires explicit casting which can throw exceptions if you cast improperly. The only thing that Lua does that C# doesn't is that it's dynamically typed, which means you can easily type back and forth from objects safely. You can always just have a variable typed object, a collection that stores objects, a Dictionary of objects, etc.Ī Dictionary is pretty much exactly what a Lua table is. ![]() Return NULL in function that should return a vector. Your code snippet is checking to see if a position is zero or the rotation is the identity, which is not the same thing as checking for null. But this is ONLY for if you need something that could be of any type, and get serialized by unity.Īgain, 'object' is the datatype that ALL structs/classes/delegates/anything inherits from in C#. The NULL return value would only be valid if you were returning a pointer to a Normal object, NULL represents a null pointer, not a null object. 132k 22 241 353 asked at 15:03 stingalimian galimian 27 3 if (x null) is the check to see if x is null. I actually wrote something for that as well. if this something that you want to create that's serializable, but dynamic in type. So what's the point of this variable? Why not just have 2 separate variables for each. you never show a situation where you don't know what type of value is in it. Like I said, in your use case you show above. your code should be more explicit about its types. Only be doing this if you need a variable that can store any kind of object. ![]() Note though, this is slow, as it causes boxing. It also actually has an implementation with generics like previously suggested, but you'll see its limitations in the regard of your use case. It also supports some types that are specific to unity, like Color and Vector3. I have my own ConvertUtil that I use that has default states for values, and performs conversion in a manner that I prefer: Of course, if you don't know the type that is being stored in it, you may get casting exceptions if you attempt to cast "hello world" to a float.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |