Thanks!
Fianally i was able to solive it, i am an experienced C# developer but quite new in unity.
This is what it did (maybe it helps someone else):
I created a 'ButtonPressedBehaviour' script and attached it to the button.
The script defines a global "pressedState" variable.
public class ButtonPressedBehaviour : MonoBehaviour
{
public bool pressedState;
// Use this for initialization
void Start ()
{
pressedState = false;
}
// Update is called once per frame
void Update ()
{
}
void OnPress(bool pressed)
{
if (pressed)
{
Debug.Log("Now is pressed");
pressedState = true;
}
else
{
pressedState = false;
Debug.Log("Now is released");
}
}
}
The "magic" happens here => The OnPress function is called automatically, when the script is attached to the UIButton.
How is this done internally?
Does UIButton (or a base class of it) use reflection and search for attached scripts that define an "OnPressed" method?
In my playerControler script (that controlls the movement of the player) i added two variables for the two UIButtons.
I use "GetComponent<ButtonPressedBehaviour>" to get the script from the assigned UIButtons and depending on the value of "pressedState" i control the movement of the player.
thx
Hannes