- Home /
Converting .cs to .js
I need somebody to help me convert this to .js, i have attempted to change a different code from .cs to .js using a converter but I don't know how to code so I was just wondering if somebody could help me, anyways if you know how to do this please help. Thank you.
"using UnityEngine; using System.Collections;
public class ShootSound : MonoBehaviour {
public AudioSource someSound;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Mouse0)) {
someSound.Play ();
}
}
} "
1.) Where's your attempt?
2.) *Why* are you converting from C# to JS? $$anonymous$$ost people try to do the reverse!
$$anonymous$$any people find Unityscript more understandable and don't appreciate constant unwarranted browbeating from C# users. But yes, "here, convert this code for me!" is really not at all what UnityAnswers is about. If you have a specific question about something you don't understand in C#, ask that.
I'm not browbeating - I'm asking the reason for tbe request. If it's as simple as "because the rest of the project is in javascript" it may be that the OP is unaware that the two languages can exist side-by-side in the same project. Currently, there is no obvious benefit from conversion.
Answer by AurimasBlazulionis · Nov 12, 2016 at 10:12 AM
Here are few things you have to do in order to convert the code:
In all variables, move their type after the name of the variable and add a column between the name and the type. So in your case
AudioSource someSound
should be written assomeSound : AudioSource
Then, you have to change all voids to function. If it is a float or bool, you have to change it to function and add
: returnType
just before the {. Keep in mind, that booleans in JS areBoolean
and in c#bool
.In the functions you also have to change the input variables the same way you do in 1).
If the c# script is not MonoBehaviour, then change the
:
toextends
. Otherwise, you can just remove the class line.All
using
should be replaced withimport
.
Your answer
Follow this Question
Related Questions
Having a GUI text as a int 3 Answers
A string converted from Json cant become "smart" and understand variables in my code, true or false? 1 Answer
Turn Strings[] into vars[]? 1 Answer
Problem Converting GUI to World Coords in Editor 2 Answers
[UNSOLVED] How to use Flooded Grounds asset in URP? 0 Answers