- Home /
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);
}
you're more likely to get help is you include information on the bugs or any error messages, etc.