Hello everyone,
I am trying to rotate my object with these codes, actually they work with key controls but they don’t work with touch or mouse functions. How should i modify these to make them work with touch or mouse functions either?
public float smooth = 2.0F;
public float tiltAngle = 30.0F;
bool rotateLeft = false;
bool rotateRight = false;
voidUpdate() {
if (Input.touchCount > 0)
{
Touchtouch = Input.GetTouch (0);
if (touch.position.x < Screen.width/2)
{
rotateLeft = true;
}
if (touch.position.x > Screen.width/2)
{
rotateRight = true;
}
if(Input.touchCount == 0)
{
if(rotateLeft == true)
rotateLeft = false;
if(rotateRight == true)
rotateRight = false;
}
Debug.Log("Rotate LEFT " + rotateLeft);
Debug.Log("Rotate RIGHT " + rotateRight);
}
if(rotateLeft == true)
{
floattiltAroundZ = -Input.GetAxis("Horizontal") * tiltAngle;
Quaterniontarget = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}else
{
floattiltAroundZ = -Input.GetAxis("Horizontal") * tiltAngle;
Quaterniontarget = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
if(rotateRight == true)
{
floattiltAroundZ = Input.GetAxis("Horizontal") * -tiltAngle;
Quaterniontarget = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
else{
floattiltAroundZ = Input.GetAxis("Horizontal") * -tiltAngle;
Quaterniontarget = Quaternion.Euler(0, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
}
}