Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jan 23, 2015 at 08:58 AM by SaraCecilia for the following reason:

Duplicate Question

avatar image
0
Question by IWannaTaco · Jan 23, 2015 at 07:10 AM · c#javascriptconvert

Need help converting javascript to c# script

I got this javascript code i need to convert it to c# and i'm having some troubles. I've tried many things and it just won't convert and work. Here is the code

JavaScript Code:

  #pragma strict
  private var formNick = "";
  private var formPassword = "";
  var formText = ""; 
   
  var URL = "http://gameserver.com/login.php"; //Not actual site
  var hash = "hashcode"; 
   
  private var textrect = Rect (10, 150, 500, 100); 
   
  function OnGUI() {
      GUI.Label( Rect (10, 10, 80, 20), "Your Nick:" ); 
      GUI.Label( Rect (10, 30, 80, 20), "Your Pass:" );
   
      formNick = GUI.TextField ( Rect (90, 10, 100, 20), formNick ); 
      formPassword = GUI.TextField ( Rect (90, 30, 100, 20), formPassword ); 
   
       if ( GUI.Button ( Rect (110, 60, 100, 20) , "Register" ) )
       {
           Register();
       }
      if ( GUI.Button ( Rect (10, 60, 100, 20) , "Login" ) ){
          Login();
      }
      GUI.TextArea( textrect, formText );
  }
   
   function Register() {
       Application.LoadLevel("Menu_Register");
   }
   
  function Login() {
      var form = new WWWForm(); 
      form.AddField( "myform_hash", hash ); 
      form.AddField( "myform_nick", formNick );
      form.AddField( "myform_pass", formPassword );
      var w = WWW(URL, form); 
      yield w; 
      if (w.error != null) {
          print(w.error); 
      } else {
          print("Test ok");
          formText = w.data;
          if (formText.Contains("Logged In Successful, Redirecting now..."))
          {
              Application.LoadLevel("Menu_Lobby");
  //            PhotonNetwork.playerName = formNick;
          }
          w.Dispose(); 
      }
  }
   
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

2 Replies

  • Sort: 
avatar image
1

Answer by SaraCecilia · Jan 23, 2015 at 08:57 AM

For future reference, how to convert your script between Unityscript/Javascript and C#: http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html

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
avatar image
0

Answer by zharik86 · Jan 23, 2015 at 07:28 AM

Ok, I converted for you, but you must learn, how converted script youself. Hope, this convertation is good start point to you.

  private string formNick = "";
  private string formPassword = "";
  public string formText = ""; 
   
  public string URL = "http://gameserver.com/login.php"; //Not actual site
  public string hash = "hashcode"; 
   
  private Rect textrect = new Rect (10, 150, 500, 100); 
   
  void OnGUI() {
   GUI.Label(new Rect (10, 10, 80, 20), "Your Nick:"); 
   GUI.Label(new Rect (10, 30, 80, 20), "Your Pass:");
   
   formNick = GUI.TextField(new Rect (90, 10, 100, 20), formNick); 
   formPassword = GUI.TextField(new Rect (90, 30, 100, 20), formPassword); 
   
   if (GUI.Button(new Rect (110, 60, 100, 20), "Register")) {
    Register();
   }
   if (GUI.Button(new Rect (10, 60, 100, 20), "Login")) {
    StartCoroutine(this.Login()); //or use StartCoroutine("Login");
   }
   GUI.TextArea(textrect, formText);
  }
   
  public void Register() {
   Application.LoadLevel("Menu_Register");
  }
   
  public IEnumerator Login() {
   WWWForm form = new WWWForm(); 
   form.AddField( "myform_hash", hash ); 
   form.AddField( "myform_nick", formNick );
   form.AddField( "myform_pass", formPassword );
   WWW w = WWW(URL, form); 
   yield return w; 
   if (w.error != null) {
    print(w.error); 
   } else {
    print("Test ok");
    formText = w.data;
    if (formText.Contains("Logged In Successful, Redirecting now...")) {
     Application.LoadLevel("Menu_Lobby");
     //PhotonNetwork.playerName = formNick;
    }
    w.Dispose(); 
   }
  }

I hope that it will help you.

Comment
Add comment · Show 2 · 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 IWannaTaco · Jan 23, 2015 at 11:38 PM 0
Share

Assets/Players & Controls/Extra/Login_Controller.cs(40,25): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected

ERROR

avatar image zharik86 · Jan 24, 2015 at 09:26 AM 0
Share

@IWannaTaco Please, write line code, where error.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help converting C# to Javascript. 1 Answer

Can someone convert this into javascript? :) 1 Answer

How can I change this C# code into Javascript? 0 Answers

C# to UnityScript conversion help. 0 Answers

Convert to JavaScript 1 Answer


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