Question by
Bentoon · Aug 09, 2016 at 10:35 PM ·
c#rotate objecttouchphasetouchcount
Rotate and object with Touch
Hello!
Simple Question I hope. I have a script that allows me to rotate an object with my mouse and I am trying to get to work on touchscreen with touchPhase and I can't get it to work:
Here is my script:
void Update () {
if (Input.GetMouseButtonDown(0))
{
f_difX = 0.0f;
}
else if (Input.GetMouseButton(0))
{
f_difX = Mathf.Abs(f_lastX - Input.GetAxis ("Mouse X"));
if (f_lastX < Input.GetAxis ("Mouse X"))
{
i_direction = -1;
transform.Rotate(Vector3.up, -f_difX);
}
if (f_lastX > Input.GetAxis ("Mouse X"))
{
i_direction = 1;
transform.Rotate(Vector3.up, f_difX);
}
f_lastX = -Input.GetAxis ("Mouse X");
}
else
{
if (f_difX > 0.5f) f_difX -= 0.05f;
if (f_difX < 0.5f) f_difX += 0.05f;
transform.Rotate(Vector3.up, f_difX * i_direction);
}
}
Thanks !
~be
Comment
Here is the script I normally use for touch
It's in the Update Function
I simply need it to rotate an object like above
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.$$anonymous$$oved) {
percentage -= touch.deltaPosition.x * speed / Screen.height;
percentage = $$anonymous$$athf.Clamp01(percentage);
iTween.PutOnPath(gameObject,path,percentage);
iTween.PutOnPath(gameObject,movePath,percentage);
iTween.PutOnPath(lookTarget,lookPath,percentage);
}
}
Thanks !!
~be
Your answer
Follow this Question
Related Questions
Rotating a 2D overlap box based on another object's rotation. 1 Answer
I want to make a bot which simulate the maze solver using left hand rule ( wall follower). 0 Answers
What is wrong with my rotation code? (i am new to coding) 1 Answer
Rotating a Model 1 Answer
TouchPhase.Began hold problem 0 Answers