Unity-Object引用未设置为对象的实例

时间:2017-10-18 22:38:09

标签: c# unity3d

Image Here 我正在尝试做这个事情,我在输入字段中输入一个单词,然后将其加密到L337外壳中,结果在文本对象中输出。但我不断收到错误对象引用未设置为对象的实例,它指向

inputText = input.text;
 output.text = inputText;

我还是一个菜鸟。如果有人可以帮助我,我会很感激。

public class Encryption : MonoBehaviour
{
public InputField input;
public Text output;
string inputText;

public Toggle L337Toggle;

 void Start()
{
    output = GetComponent<Text>();
    input = GetComponent<InputField>();

    L337Toggle.isOn = false;

}
private void Update()
{
   inputText = input.text;
    output.text = inputText;

    var textEncryption = new TextEncryption(inputText);
    var L337Encryption = new L337Encryption(textEncryption);

    if (Input.GetKeyDown("enter"))
    {
        if (L337Toggle.isOn == true)
        {
            string result = L337Encryption.encrypt();
        }
    }
}


public interface IEncryption
{
    string encrypt();
}

public class TextEncryption : IEncryption
{
    private string originalString;

    public TextEncryption(string original)
    {
        originalString = original;
    }
    public string encrypt()
    {
        Debug.Log("Encrypting Text");
        return originalString;
    }
}

public class L337Encryption : IEncryption
{
    private IEncryption _encryption;

    public L337Encryption(IEncryption encryption)
    {
        _encryption = encryption;
    }
    public string encrypt()
    {
        Debug.Log("Encrypting L337 Text");
        string result = _encryption.encrypt();
        result = result.Replace('a', '4').Replace('b', '8').Replace('e', '3').Replace('g', '6').Replace('h', '4').Replace('l', '1')
            .Replace('0', '0').Replace('q', '9').Replace('s', '5').Replace('t', '7');

        return result;
    }
}

}

0 个答案:

没有答案