x


Convert C# code to javascript

Hi!

I've a problem with a C#script that i'm trying to convert to javascript. But i've no idea of C# sintax. Can somone convert this for me?

Thanks in advance

Transfo camera r = (Transform)Instantiate(ragdollsToCreate[i], objectsToKill[i].transform.position, objectsToKill[i].transform.rotation);

       if (!r)
       {
         Debug.LogError("Example.Update() " + name + " could not Instantiate " + ragdollsToCreate[i].name);
       }
       else
       {
         // get AdvancedRagdoll script
         AdvancedRagdoll ar = (AdvancedRagdoll)r.GetComponent("AdvancedRagdoll");

         if (!ar)
         {
          Debug.LogError("Example.Update() " + name + " could not get AdvancedRagdoll from " + r.name);
         }
         else
         {
          // store ragdoll reference
          ragdolls.Add(ar);

          // synch ragdoll to current object animation pose
          ar.SynchRagdollIn(objectsToKill[i].transform);
         }
       }

       // destroy object
       Destroy(objectsToKill[i]);
more ▼

asked Jun 03 '11 at 05:30 PM

danielreyvega gravatar image

danielreyvega
1 5 5 6

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You most likely aren't going to get people here who are going to spend their time converting your script.

Become a better Unity developer and learn to code in both languages. Trust me, down the line you'll need to be able to do both if you want to become successful with Unity.

Take a look at this thread for a good read on the syntax differences.

more ▼

answered Jun 03 '11 at 06:21 PM

Meltdown gravatar image

Meltdown
5.6k 18 25 49

Ya I had noticed, but I posted my answer not knowing that you had answered the question and didn't feel like deleting mine

Jun 03 '11 at 06:38 PM Peter G
(comments are locked)
10|3000 characters needed characters left

First, the code you posted is full of errors if it is C#.

Transfo camera r = (Transform)Instantiate();
//This isn't a legal line.  It looks like it is supposed to be this:
Transform r = (Transform)Instantiate();

Another error:

if(!r)
//This is legal in js, but in C#, you must do this:
//if(r == null)

But besides for that there isn't really anything that should cause problems in translating that aren't obvious changes. Identify variables and declare them in js syntax.

The only thing to remember is that casting in js can only be done with as syntax.

And see this answer for a more in-depth explanation.

http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

more ▼

answered Jun 03 '11 at 06:25 PM

Peter G gravatar image

Peter G
15k 16 44 136

thats the link I gave him :p

Jun 03 '11 at 06:35 PM Meltdown
(comments are locked)
10|3000 characters needed characters left

Thanks Meltdown en peter!

While you'r answering my question, i've tried to convert only the changes i need to c#.

So thank's again, and sorry to ask you that things but i'm learning animation, 3d design, texturing and javascript. If i have to learn C# too, my head will explode for sure.

Cheers!

more ▼

answered Jun 04 '11 at 06:47 AM

danielreyvega gravatar image

danielreyvega
1 5 5 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5091
x4172
x3464

asked: Jun 03 '11 at 05:30 PM

Seen: 1800 times

Last Updated: Jun 04 '11 at 06:47 AM