• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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 yorumpark · Oct 18, 2011 at 04:00 PM ·

can anybody convert this script to js? (C#)

hi, can anybody convert this script to js? i need this? c# script:


using UnityEngine;

using gui = UnityEngine.GUILayout;

public class GameMenu : MonoBehaviour

{

 public GameObject PlayerPrefab;

 string ip = "127.0.0.1";



 public void CreatePlayer()

 {

     connected = true;

     var g = (GameObject)Network.Instantiate(PlayerPrefab, transform.position, transform.rotation, 1);

     g.camera.enabled = true;

     camera.enabled = false;

 }

 void OnDisconnectedFromServer()

 {

     connected = false;

 }

 void OnPlayerDisconnected(NetworkPlayer pl)

 {

     Network.DestroyPlayerObjects(pl);

 }

 void OnConnectedToServer()

 {

     CreatePlayer();

 }

 void OnServerInitialized()

 {

     CreatePlayer();

 }

 bool connected;

 void OnGUI()

 {

     if (!connected)

     {

         ip = gui.TextField(ip);

         if (gui.Button("connect"))

         {

             Network.Connect(ip, 5300);

         }

         if (gui.Button("host"))

         {

             Network.InitializeServer(10, 5300, false);

         }

     }

 }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Julien-Lynge · Oct 18, 2011 at 04:30 PM

In response to your question

can anybody convert this script to js? (C#)

The answer is: Yes! You can!

Unity's javascript and C# implementations are very similar. Here are a couple of resources to get you started:

  • http://col000r.blogspot.com/2009/12/unity-making-switch-from-javascript-to.html

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

You can also check out this answer for a possible way to directly convert the script:

http://answers.unity3d.com/questions/21573/converting-code-from-javascript-to-c.html

Comment
Add comment · Show 3 · 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
avatar image Julien-Lynge · Nov 13, 2011 at 01:32 AM 1
Share

BTW: this seems to be such a common question that I've created a blog post I can just send people to in the future:

http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

If anyone has any other good links for resources on converting, let me know and I'll add them to the list.

avatar image alucardj · Mar 04, 2013 at 07:25 AM 1
Share

Here's some links I found useful in converting between C# and JS :

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

http://www.unifycommunity.com/wiki/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?

http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

avatar image Julien-Lynge · Mar 14, 2013 at 10:17 PM 0
Share

Very cool, thanks! I'll add those to the list.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to read "mp3" or "other Audio" file from SDcard in runtime 0 Answers

Can you use Unit JS script like standard JS DOM? 1 Answer

Picking up an object 2 Answers

Creating A particle effect swirle 0 Answers

XML Encryption 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges