Unity 4.6 InputFields need help

Hi.So what i am trying to do is a test scene where i want to use the InputFields to change some variable values.Like most here I have not used these Inputfields before so I need help.
After some research i found this code but i get errors that it cannot convert from string to float and i am not even sure it is a good code.Please help ty

 public InputField leftInput;

    void Awake()
    {
    leftInput.onSubmit.AddListener((value) => SubmitName(value));
    leftInput.validation = InputField.Validation.Float;
    submitButton.onClick.AddListener(() => SubmitName(leftInput.value));
    }

    void SubmitName(float value)
    {
    	//change a value with the input
        oldvalue = value;
    }

1 Answer

1

The value submitted by input field is a string (regardless of validation), so you need to convert the value.

Single.TryParse documentation should help

can you show me exactly how to do this because i am not quite sure

Change the submit function: void SubmitName(string value) { float number; if (Single.TryParse(value, out number)) { oldvalue = number; } else { Debug.Log("cannot parse value: " + value); } }

i am getting the following error: The name `Single' does not exist in the current context I tryed it myself before asking and was getting the same error and was thinking i am doing something wrong but i see it happends here too.

At the top of the file add: using System;

can you help me with one more thing? Random' is an ambiguous reference between UnityEngine.Random' and `System.Random' I get this after setting using System