I am new to Unity and recently I am struggling with the joystick stuff. I want to change the position of the joystick by finger tap. For example, if I touch the center of the screen, the joystick will show in the center, too.
Here is my code:
private void Update()
{
Touch firstTap = Input.touches[0];
if (firstTap.phase == TouchPhase.Began)
{
m_StartPos = firstTap.position;
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
}
else if (firstTap.phase == TouchPhase.Ended)
{
m_StartPos = new Vector3(500f, 500f, 0);
transform.position = m_StartPos;
UpdateVirtualAxes(m_StartPos);
}
}
I add the Update()
function in the joystick script. The position does change when I tap the screen but the onGrag()
is never called when I move my finger.