Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PwnerYoder · Nov 12, 2016 at 07:43 AM · converting

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 ();
     }
 }

} "

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Nov 12, 2016 at 07:46 AM 0
Share
 1.) Where's your attempt?
 2.) *Why* are you converting from C# to JS? $$anonymous$$ost people try to do the reverse!
avatar image Eric5h5 tanoshimi · Nov 12, 2016 at 08:37 AM 0
Share

$$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.

avatar image tanoshimi Eric5h5 · Nov 12, 2016 at 11:18 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AurimasBlazulionis · Nov 12, 2016 at 10:12 AM

Here are few things you have to do in order to convert the code:

  1. 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 as someSound : AudioSource

  2. 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 are Boolean and in c# bool.

  3. In the functions you also have to change the input variables the same way you do in 1).

  4. If the c# script is not MonoBehaviour, then change the : to extends. Otherwise, you can just remove the class line.

  5. All using should be replaced with import.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges