|
I've been fighting this problem for a couple of hours and have finally decided to ask my first question on UA. I have a line of code that works fine in C# But when I try and translate it to JS I keep getting errors. I've tried a couple of different ways of writing this line, inlcuding: and But neither way will compile for me. I keep getting the error "UCE001: ';' expected. Insert a semicolon at the end." for this line of code. I can not for the life of me figure out what simple mistake I am making in this translation. I have not coded much in C# (at least inside of Unity anyways), I've mainly used JS (but never outside of Unity). So I know it has to be something simple, so any help would be greatly appreciated. EDIT - Well I feel dumb, after some sleep, I went through my code again and found out that there was a small bug elsewhere in the code that was the actual cause of the ball not to follow it's trajectory. All of the following versions of code work now: But I did learn a lot about casting in JS. Thanks everyone for there help, and for putting up with my dumb 1st question.
(comments are locked)
|
|
I don't code in JS, so forgive me if there's a more elegant solution. I poked around and it appears from my testing like JS returns a GameObject (rather than Object like C#) on Instantiate calls. So, your error seems to be that Unity doesn't want to typecast a GameObject into a Transform. What I did to get it working is treat it as a GameObject and grab the associated transform: Good luck. Also, this might enlighten you: http://forum.unity3d.com/threads/3276-Typecasting-in-Javascript
Aug 17 '11 at 08:11 AM
Julien.Lynge
The outer ()'s can be left out. But other then that this should work.
Aug 17 '11 at 10:05 PM
Joshua
(comments are locked)
|
|
Removing "as Transform" from first statement can solve your problem.
(comments are locked)
|
|
use transform instead of Transform first, since JS is case sensitive language. Again it will be better if you instantiate the tansform object inside a function if you have to create it at runtime(though I dont know where exactly you are declaring variable.) If you cannot get answer from my post it do not suits you to unknowingly mark it wrong, bear it in mind.
Aug 17 '11 at 10:02 AM
rushikesh90
I'm not the one who marked it wrong.
Aug 18 '11 at 06:13 AM
Game_Smith
(comments are locked)
|

@NOAA_Julien
That fixed the compiler error, but the code does not function the same as it did.
Before in the C# version, the bullet would fire correctly out of the cannon. But now when it fires, the bullet drops at it's spawn point instead of moving along it's trajectory.
I'm not for sure if this is caused by the differences in how Unity handles the two scripting languages or not, I'm not familiar enough with both of them to be sure.
@MohsenEbrahimi
You suggestion worked as well, but it will only let me mark one answer as correct.