|
I am trying to convert this Javascript to C#:
When I play the game, I am getting this error "InvalidCastException: Cannot cast from source type to destination type." What am I doing wrong?
(comments are locked)
|
|
Have you tried replacing
with
? If you need to get bullet as game object, you could do something like this: The Transform... version worked. I am a http://VB.NET programmer so I am learning the C# syntax. I know this may not be Unity related, but it has do with this Instantiate syntax. Why do you need the syntax '(Transform)' in front of Instantiate? Thank you for the help!
Jul 30 '10 at 01:28 PM
Jeff 3
When it worked for you, you may consider "accepting" the answer (click the "check" symbol left of the up/down-vote arrows). Regarding "(Transform)": That's needed because Instantiate simply returns an Object, which you need to cast to the correct type "Transform". Since Unity 2.6 some methods are available in generic versions which makes this a bit less cumbersome, e.g. GetComponent() would return "MyScript" as such, so no type-casting needed. Some more info on typecasting: http://en.csharp-online.net/Typecasting or http://en.wikipedia.org/wiki/Type_conversion
Jul 30 '10 at 05:26 PM
jashan
(comments are locked)
|
