|
A problem people new to Unity and scrpting may run in: I have a variable. I know it will be only assigned to a single GameObject or Component for the whole time, I also know that dynamic/inference typing is much slower than static typing (even if the variable is assigned right away in function Awake and then never changes), so I want to avoid it. What I don't know is: Is there a way to find out (with a Debug.Log or something) of what type my dynamically typed variable currently is? (So that I can then assign that type statically) Thanks & Greetz, Ky.
(comments are locked)
|
|
So I take that as a "yes, it is possible"? But as this question is ment for very beginners like myself, this link does little more than baffle me about how such an easy question can lead to so much scary code :p ^^' I still have no idea how to get the information I want... Plus this appears to explain the usage for C# only? Which is as of yet useless, as Unity2.6.1 doesn't support dynamic typing for C# yet, but only for UnityScript...
Jan 29 '10 at 02:22 AM
SisterKy
It's a function you can use on anything. "Debug.Log(myVariable.GetType() );"
Jan 29 '10 at 04:44 AM
Jessy
Ah, now I see! Thank you! I wasn't aware that you could use functions inside Debug.Log();
Jan 29 '10 at 11:06 PM
SisterKy
(comments are locked)
|
|
The documentation for each function indicates the return type. For example, you mentioned GameObject.Find(), which has this prototype in the docs:
i.e. it returns a GameObject, so
Note that if you're using the built in code editor, highlighting a function name and hitting F1 will load the docs in your browser. I hope that helps. Hmm... that's weird... as I wrote, I had assumed that it's a GameObject, but for some reason it (repeatedly) threw me errors a few days ago... unfortunatly I don't have those scripts anymore and seem to be unable to reproduce those errors... Oo hmmm... well, thank you for your answer, anyway... =)
Jan 29 '10 at 11:09 PM
SisterKy
(comments are locked)
|
|
Assuming the variable is a reference type (not a direct value like "5" or "blah"), you don't even need GetType():
(comments are locked)
|
