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 Guzaii · Aug 24, 2015 at 08:48 AM · c#javascriptarraylistjs to c#

I tried to convert my Dev Console to C# from JS

I tried to convert my Dev Console to C# from JS... But i don't know that much of C#.. So i got alot of bugs. Please can someone help me?

// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden

// Do test the code! You usually need to change a few small bits.*

my error codes:

Assets/DevConsole.cs(65,25): error CS0150: A constant value is expected


Assets/DevConsole.cs(94,60): error CS0029: Cannot implicitly convert type UnityEngine.GameObject[]' to UnityEngine.GameObject'


Assets/DevConsole.cs(95,33): error CS1579: foreach statement cannot operate on variables of type UnityEngine.GameObject' because it does not contain a definition for GetEnumerator' or is not accessible


Assets/DevConsole.cs(135,35): error CS0019: Operator ==' cannot be applied to operands of type char' and string'

`

 using UnityEngine;
 using System.Collections;
 
 public class DevConsole : MonoBehaviour {
     bool  isDev;
     
     string startText;
     Rect consolewindow= new Rect(0,0,375,600);                 // ConsoleWindow properties
     private ArrayList consoleInput;                 // Array for Console Text
     private string inputField = "";                    // Inputfield
     private Vector2 scrollPosition; 
     private bool  developerconsole=false;
     private string processed;
     
     private GameObject player;
     
     
     GameObject bluecube;                                    //EXAMPLE Object
     
     string Password = "";
     GUISkin guiSkin;
     
     
     //*********************************************************************
     void  Awake (){
         //DontDestroyOnLoad (transform.gameObject);
         //STARTTEXT Example
         startText = "# Developer console version 1.0f.0.1f\n" + "# .help for Help.\n" + "# This console is meant for Devs.\n" + "# Please use with Caution";
     }
     //*********************************************************************
     void  Start (){
         ConsoleText(startText);
         if(PlayerPrefs.GetInt("IsDev")==1){
             isDev=true;
         }
         consolewindow = new Rect(0,0,375,Screen.height/1.5f);
     }    
     
     //*********************************************************************
     void  Update (){
         
         //********************************
         if(Input.GetKeyDown (KeyCode.Pause))                //Console enable/disable with pressing TAB
         {
             if(developerconsole == false)                    //if false
             {    
                 developerconsole = true;                    //Console enable
             }                                                
             else
             {
                 developerconsole = false;                    //Console disable
             }                    
         }
         
         //********************************
         //Commands    EXAMPLES (Here you need to add your functions)
         
         
         if(isDev == false){
             
             
             switch(processed)
             {
             case ".help":    ConsoleText("# .unlock (password)\n" + "# .reset");     break;
             case ".unlock " + Password:    isDev=true; PlayerPrefs.SetInt("IsDev",1); ConsoleText("# Console Unlocked!\n" + "# USE CAREFULLY!");        break;
             case ".unlock": ConsoleText("# You must enter a password!\n" + 
                                             "# If the password is wrong,\n" + 
                                             "# The console will not say Unlocked.");        break;
             }
         }
         
         if(isDev == true){
             
             switch(processed)
             {
                 
                 
             case ".help":             ConsoleText("# .lock\n"    +
                                              "# .spawn\n"    +
                                              "# .load\n(End with game name or menu)\n"    +
                                              "# .spawn\n"    +
                                              "# .spawn_endless (Spawns endless amount of Test Cubes)(Stop with .stop)\n" +
                                              "# .destroy_all\n"    +
                                              "# .reset");         break;
                 
                 //Examples
             case ".load game1":    Application.LoadLevel("game1"); ConsoleText("# Loaded - Game -");    break;
             case ".load game2":    Application.LoadLevel("game2"); ConsoleText("# Loaded - Game -");    break;    
             case ".load menu":    Application.LoadLevel("game2"); ConsoleText("# Loaded - Game -");    break;    
                 
                 
                 //        case ".spawn":            Instantiate (spawn, transform.position+(transform.forward*2), transform.rotation); ConsoleText("# spawned Object finished\n"); break;
             case ".spawn_endless":    Instantiate (bluecube, transform.position+(transform.forward*2), transform.rotation); break;        //Stop with any Input into console
             case ".destroy_all":    GameObject objects= GameObject.FindGameObjectsWithTag ("Object");
                 foreach(GameObject delete in objects)
                     Destroy(delete);
                 break;
                 
             case ".lock": isDev=false; PlayerPrefs.SetInt("IsDev",0); ConsoleText("# Console Locked.");    break;
                 
                 //case ".fly": ConsoleText(".fly on/off"); break;
                 //case ".fly on": player.GetComponent<CharacterController>().enabled=false; break;
                 
             case ".reset": PlayerPrefs.DeleteAll(); ConsoleText("Data Reset"); break;
                 
                 
             }
         }
     }
     
     //********************************************************************
     //DO NOT CHANGE THIS SCRIPT PART
     
     void  OnGUI (){
         
         GUI.skin = guiSkin;
         
         if(developerconsole == true)    { consolewindow = GUI.Window (1, consolewindow, ConsoleWindow, "Developer console"); }
         
     }
     
     void  ConsoleWindow ( int id  ){
         scrollPosition = GUILayout.BeginScrollView (scrollPosition);
         
         foreach(string output in consoleInput)
         {
             processed = output;        
             GUILayout.BeginHorizontal();
             GUILayout.Label(output);
             GUILayout.EndHorizontal();    
         }
         GUILayout.EndScrollView (); 
         
         if ( 
             Event.current.character == "\n" &&
             Event.current.type == EventType.keyDown &&
             inputField.Length > 0
             )
         {              
             ConsoleText(inputField); 
             inputField = "";
         }
         inputField = GUILayout.TextField(inputField);    
         //    GUI.DragWindow();
     }
     
     //******************************
     //Add Console Text
     void  ConsoleText ( string Text  ){
         consoleInput.Add(Text);
     }
Comment
Add comment · Show 2
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 gjf · Aug 22, 2015 at 01:47 PM 0
Share

you're more likely to get help is you include information on the bugs or any error messages, etc.

avatar image Guzaii · Aug 22, 2015 at 01:58 PM 0
Share

Oh ok. Im not home at the moment. Will add once i can.

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Unable to disable a C# script with a JS Script 2 Answers

Distribute terrain in zones 3 Answers

Can't connect to Web socket, connection refused Unity WebGL 0 Answers

Can I use Javascript (Unityscript) for Box2D for Unity or Farseer Physics? 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