I have this lines of code that work with mouse input: when mouse is pressed and moved up, the game object rotate, and when moved down, rotate backwards. I want to do the same but with my finger touch for an AR app. Please someone help me!!!
case "BOTAO GIRO (1)":
if(botao.transform.rotation.eulerAngles.z < 100)
{
botao.transform.Rotate(Vector3.forward * speed);
}else { }
if(botao.transform.rotation.eulerAngles.z > 350)
{
botao.transform.Rotate(Vector3.back * speed);
}else { }
if (Input.GetMouseButton(0))
{
if (Input.GetAxis("Mouse Y") > 0)
{
if (botao.transform.rotation.eulerAngles.z > 100 && botao.transform.rotation.eulerAngles.z < 350)
{
Debug.Log(botao.transform.eulerAngles.z);
botao.transform.Rotate(Vector3.forward * speed);
}
}
else
{
if (Input.GetAxis("Mouse Y") < 0)
{
if (botao.transform.rotation.eulerAngles.z > 100 && botao.transform.rotation.eulerAngles.z < 350)
{
Debug.Log(botao.transform.rotation.eulerAngles.z);
botao.transform.Rotate(Vector3.back * speed);
}
}
}
}
else
{
if (Input.GetMouseButton(0) == false)
{
eixo.SetActive(false);
}
}
break;
In API eg Touch.phase
where you can find a complete implementation example.
For you it would look somewhat like eg
private Vector2 firstTouchPosition;
...
case "BOTAO GIRO (1)":
if(botao.transform.rotation.eulerAngles.z < 100)
{
botao.transform.Rotate(Vector3.forward * speed);
}
if(botao.transform.rotation.eulerAngles.z > 350)
{
botao.transform.Rotate(Vector3.back * speed);
}
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
switch(touch.phase)
{
case TouchPhase.Began:
firstTouchPosition = touch.position;
break;
case TouchPhase.Moved:
var dif = touch.position - firstTouchPosition;
if (dif.y > 0)
{
if (botao.transform.rotation.eulerAngles.z > 100 && botao.transform.rotation.eulerAngles.z < 350)
{
Debug.Log(botao.transform.eulerAngles.z);
botao.transform.Rotate(Vector3.forward * speed);
}
else if (did.y < 0)
{
if (botao.transform.rotation.eulerAngles.z > 100 && botao.transform.rotation.eulerAngles.z < 350)
{
Debug.Log(botao.transform.rotation.eulerAngles.z);
botao.transform.Rotate(Vector3.back * speed);
}
}
}
break;
}
}
else
{
exio.SetActive(false);
}
Typed on smartphone but I hope the idea gets clear
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.