Is it just me or does my Unity not want to work?
I have been using the latest version of Unity 2019 and have had no issues up until recently. For some reason, some of the things that I have coded just stopped working randomly. They were never changed and had worked perfectly fine with other projects previously (all these other projects were made with the same Unity version. However, today simple things such as running a function when a button is hovered over on or even simply displaying a value from an array just don't want to work anymore.
One example I can provide is my command console I recently started working on. From what I can see, I don't think there are any errors in the code (if I missed something please tell me, I truly appreciate all feedback) but the script just does not work. The code is:
using System;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
public class console : MonoBehaviourPunCallbacks
{
bool consoleOpen = false;
bool consoleUnlocked = false;
public GameObject dev_console;
string[] commands = new string[4];
string[] outputs = new string[4];
public InputField csInput;
public Text csOutput;
void Start()
{
initCommands();
initOutputs();
}
void initCommands()
{
//cs commands
commands[0] = "cs_clear";
commands[1] = "cs_help";
//mp commands
commands[2] = "mp_join_random";
//dev commands
commands[3] = "dev_7073";
csOutput.text += "\n(" + DateTime.Now.TimeOfDay.ToString() + ") Commands updated and loaded";
}
void initOutputs()
{
//cs outputs
outputs[0] = "Clearing...";
outputs[1] = "";
//mp outputs
outputs[2] = "Joining random room...";
//dev outputs
outputs[3] = "까불지 마.";
csOutput.text += "\n(" + DateTime.Now.TimeOfDay.ToString() + ") Outputs updated and loaded";
}
void Update()
{
if (Input.GetKeyDown(KeyCode.BackQuote))
{
if (consoleOpen == true)
{
consoleOpen = false;
dev_console.SetActive(false);
}
else
{
consoleOpen = true;
dev_console.SetActive(true);
}
}
}
public void submitEntry()
{
string input = csInput.text;
csInput.text = "";
int index = Array.BinarySearch(commands, input);
if (index < 0)
{
csOutput.text += "\n(" + DateTime.Now.TimeOfDay.ToString() + ") Unknown command, use 'cs_help' for a list of available commands.";
}
else
{
csOutput.text += "\n(" + DateTime.Now.TimeOfDay.ToString() + ") " + outputs[index];
}
if (input == commands[0])
{
csOutput.text = "";
}
if (input == commands[1])
{
foreach (var item in commands)
{
if (item == "dev_7073")
{
}
else
{
csOutput.text += item + ", ";
}
}
}
if (input == commands[2])
{
if (consoleUnlocked == true)
{
PhotonNetwork.JoinRandomRoom();
}
else
{
csOutput.text += "\n(" + DateTime.Now.TimeOfDay.ToString() + ") Error: Access Denied.";
}
}
if (input == commands[3])
{
consoleUnlocked = true;
}
}
}
Now the main issue with this code is that all commands work perfectly fine except for "dev_7073". When I enter that code, consoleUnlocked does become true which means the function had ran properly. However, the output for the code is not displayed for some reason and returns the "Unknown command" response. But why would it do that? Especially since it executes the command's function.
Any and all help is appreciated :)
Please use Debug.Log to log the lines after concatenation. $$anonymous$$aybe even use breakpoints to see what your code is doing.