Reputation: 437
I'm not able to get information from my Input Field - I'm even unable to type in a value. Input- Field - Settings
The code is:
using UnityEngine;
using UnityEngine.UI;
public class ButtonPress : MonoBehaviour {
public InputField GrasInput;
public Button playbutton;
int GrasVal=0;
private void Start()
{
Button btn = playbutton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
GrasVal++;
GrasInput.text = GrasVal.ToString();
}
}
What am I doing wrong, I wasn't able to find a solution, tried different things to solve problem (not mentioned in the code above, because none of them worked out)? All of the components (GrasInput and playbutton) are connected in the console via the _Manager and this script. (The whole project is uploadet on http://simsoeko.tk/)
Thanks and sorry, I'm just a beginner and really tried to find out why it won't work.
Upvotes: 0
Views: 5440
Reputation: 459
Maybe your scene is missing an EventSystem object. Add it under Hierarchy > create > UI > EventSystem (https://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.html)
per: https://answers.unity.com/questions/1540770/cant-click-on-input-fields.html
Upvotes: 0
Reputation: 3108
Looking at the screenshot provided, your Text
GameObjects are further down in the hierarchy, also their size seems to "contain" the inputfields, therefor they are blocking the raycasts to your InputField
s
Either detick Raycast Target
on your Text
objects.
Or move the InputField
s further down in the hierarchy (while remaining children of Canvas)
Upvotes: 3