Answer the question
In order to leave comments, you need to log in
How to make an object react only to a vertical swipe?
There is a code that moves an object along the z axis. Is there a way to make code using OnDrag so that it fixes the position of the swipe and reacts to the vertical one?
public void FixedUpdate()
{
if (Input.touchCount > 0)
{
var touch = Input.GetTouch(0);
switch (touch.phase)
{
case TouchPhase.Began:
_startPos = touch.position;
break;
case TouchPhase.Moved:
var dir = touch.position - _startPos;
var pos = transform.position + new Vector3(transform.position.x, transform.position.y, dir.y);
transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * _speed);
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, probably not to move to the value of the vector, on which you do not want to move?
everywhere in the transform position at the end add .z
transform.position.z
this would only change the Z position
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question