Using touch input to rotate AR Object with code.
Objective: Using touch input to rotate AR Object with code.
In the First we need to to know the user touch the screen, to do this we use Input.TouchCount. We use this to make sure at least user touch the screen.
To do thing with touch we use GetTouch to access position ,delta position ,number of finger touch the screen.
Note: Input.GetTouch(0) give us the first finger touch the screen, so 1 will be second and forth.
But we only need to rotate the object when we examining the object, to do this create a bool and change it to true and false when we PerformExamine and when we PerformUnExamine.
Now before checking touchCount we need to check if isExamining is true.
Hey! we want to rotate the object if the finger is moving, we do this by going further to our touch variable ,touch variable has property of enum so we can access differnt state of the touch.
To rotate object use Rotate method to do that ,remember the object is being accessed using Examinable script which we called it currentExaminableObject .This method can take different parameter but I will use the one which take x,y,z since the finger move horizontal and vertical z-axis will be zero.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Touch-deltaPosition.html
In addition when I examine this object I want to reduce its original size ,from examinable script I create a float and here are the rest of code inside the Examinable Manager.
See you into the next one.