- Home /
error CS1061 and error CS0117 scripting InputField
I'm trying to create an Input Field to send commands to a simple AI. I'm getting this error:
Assets/Scripts/InputController.cs(15,23): error CS1061: Type 'string' does not contain a definition for 'text' and no extension method 'text' of type 'string' could be found (are you missing a using directive or an assembly reference?)
From this following script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class InputController : MonoBehaviour {
private InputField input;
void Awake(){
input = GameObject.Find ("InputField").GetComponent<InputField>();
}
public void GetInput(string input){
Debug.Log (input);
input.text = "";
}
}
FYI: The 'text' parameter in the input component is highlighted in red in the MonoDevelop:
public void GetInput(string input){
Debug.Log (input);
input.text = "";
}
When I hover over it in the MonoDevelop I get the following error in a balloon message:
Error CS0117: 'System.String' does not contain a definition for 'text'
I test this in a plain new project and scene and it works.
Answer by doublemax · Oct 31, 2016 at 10:52 PM
private InputField input;
public void GetInput(string input){
Debug.Log (input);
input.text = "";
}
You have a member variable "input", which is of type InputField.
And you have a method parameter "input", which is of type string.
So there is a conflict.
Choose another name for one of the variables.
Well, now this was stupid. I am having a 10 hours blast in front of Unity, missed this one. Thank you so much!!! What would we do without the community ;) cheers!