Swipe Up and Down to rotate an object PLEASE HELP!!!
Hello,
I'm trying to rotate an object by swiping on it not by swiping on screen anywhere. I had this code which is works on swipe on any where on screen to rotate the object BUT i want to rotate the object only when we swipe on object not on anywhere on screen!! Any help is greatly appreciated.
here is my code
using UnityEngine; using System.Collections;
public class text : MonoBehaviour {
 public Transform player; // Drag your player here
 private Vector2 fp; // first finger position
 private Vector2 lp; // last finger position
 void Update () {
     foreach(Touch touch in Input.touches)
     {
         if (touch.phase == TouchPhase.Began)
         {
             fp = touch.position;
             lp = touch.position;
         }
         if (touch.phase == TouchPhase.Moved )
         {
             lp = touch.position;
         }
         if(touch.phase == TouchPhase.Ended)
         {
             if((fp.y - lp.y) > 80) // left swipe
             {
                 player.Rotate(270,0,0);
             }
             else if((fp.y - lp.y) < -80) // right swipe
             {
                 player.Rotate(90,0,0);
             }
             else if((fp.y - lp.y) < -80 ) // up swipe
             {
                 // add your jumping code here
             }
         }
     }
 }
}
Thanks!
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Problem with swipe and player jump 2 Answers
Unity game and lower android API level 1 Answer
1 Restart Scene multiple levels. Is this possible? - C# - 1 Answer
Problem with swipe and Gyro 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                