Sorry for the poor translation.
I want to prevent character movement while editing inputfield
At first, I blocked keyboard input by giving a bool value as IsActive Function , but another problem occurred, so this method cannot be used.
As shown in the picture, the character also moves during inputfiled input.
How to I solve it?
Thank you.
If you’re using the UGUI system, you can use the EventSystem to find the currently selected UI object, like so: var selectedObject = FindObjectOfType<EventSystem>().currentSelectedGameObject;
Then if selectedObject
is not null, you can check that it has an InputField component with
GetComponent<InputField>()
.
You could even write an extension method like this:
public static class EventSystemExtensions
{
public static bool IsTypeFocused<T>(this EventSystem self)
{
return self.currentSelectedGameObject.GetComponent<T>() != null;
}
}
and then do the check with if(FindObjectOfType<EventSystem>().IsTypeFocused<InputField>()) { /* code here */ }