|
I began using #pragma strict when my project was updated from 2.x to 3.3 as it added into my javascript and I was reading all the good things it forces you to do, so I stuck with it. Using the script example from the Unity website, I was not getting the results I expected, and for newbies to OOP and Unity, I think my question / comment might help others. when using examples scripts such as ... var ETD_TextMesh: TextMesh = ETD.GetComponent(TextMesh); without #pragma strict, this will work! With #pragma strict you need to type it.... var ETD_TextMesh: TextMesh = (ETD.GetComponent(TextMesh) as TextMesh); (where ETD is a gameobject set by using a find) So my question was if the conversion is going to add the #pragma strict, and its better to use, why don't we make sure to add typing and such to our exmples, so the newbies (like me) don't bang their heads for so long. : ]
(comments are locked)
|
|
Better yet, use No need to type it as it's implicitly set to TextMesh, and there's no issues with it needing casting as it returns a TextMesh not a component in the process of learning C#, but when in a crunch I can churn out more javascript at a faster rate, but it my goal to use C# only on the next project!!
Jun 16 '11 at 05:21 PM
wkmccoy
@wkmccoy: this isn't about C#. Mike posted Javascript, and C# has the same issues with casting in any case.
Jun 16 '11 at 05:23 PM
Eric5h5
I actually caught that and wanted to repost to ask what does the <> do that is so special, but thought I would just go look it up. I see your posts all the time, so let me say thanks, your comments have helped me out in the past many times, keep posting!! : ]
Jun 16 '11 at 06:23 PM
wkmccoy
It's called generics, and basically it compiles in a way which creates a new function specifically for TextMesh (Or whatever you put in there)
Jun 16 '11 at 11:36 PM
Mike 3
thank you, could not find anything on that, as google searches turn up so much other stuff!!
Jun 29 '11 at 01:20 AM
wkmccoy
(comments are locked)
|

because then you need to explain the TextMesh part. var ETD_TextMesh: TextMesh = ETD.GetComponent(TextMesh); is simplified and maybe slower but its easier to understand and less to remember. I agree it should be explained correctly in the examples but I think that this is the reason why its not.
I agree, first time I ran into this I was also banging my head on this exact problem. There should perhaps be a list of things you need to know when changing to strict typing.