- Home /
Question by
Chasvortex · Feb 01, 2013 at 08:03 PM ·
mousetouchnoobconvert
Touch / mouse code.
I have a piece of a script I am using for camera control, and I want to incorporate touch into it, I have done the following. The mouse code works however the touch says it cannot convert type unity.engine.touch to 'bool' Any help?
if (Input.GetMouseButton(0))
{
if (Joycheck.transform.position.z == 0){
xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
////////OrbitAngle
//Clamp the vertical axis for the orbit
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// set camera rotation
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.rotation;
rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
transform.rotation = rotation;
}
}
// Touch code
if (Input.GetTouch (0))
{
if (Joycheck.transform.position.z == 0){
xDeg += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
yDeg -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
////////OrbitAngle
//Clamp the vertical axis for the orbit
yDeg = ClampAngle(yDeg, yMinLimit, yMaxLimit);
// set camera rotation
desiredRotation = Quaternion.Euler(yDeg, xDeg, 0);
currentRotation = transform.rotation;
rotation = Quaternion.Lerp(currentRotation, desiredRotation, Time.deltaTime * zoomDampening);
transform.rotation = rotation;
}
}
Comment
Best Answer
Answer by DeveshPandey · Feb 02, 2013 at 05:19 AM
Input.GetTouch (0) will return the first Touch on the screen and its not a bool value it is a Touch type.
Have a look below -
// Incorrect
if (Input.GetTouch (0))
{
// your code
}
// Correct way
if(Input.touchCount == 1) // when touch with one finger
{
// your code
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Is it possible to test Touch event without IOS? 1 Answer
Can I Use This Code For IOS? 1 Answer
Convert Touch input to Mouse input C#? 1 Answer
Convert Mouse Input to Touch Input 0 Answers