Question by
NU96flintj · Aug 19, 2017 at 12:54 AM ·
moveto
Make an object go to a location with only one touch
Hi all,
I'd like to make a ball go to a specific point with only one touch. Each time the screen is pressed the ball moves to a different location. I only want it to move once and then reset. Thank you. My code is below.
// Use this for initialization
void Start()
{
Vector3 position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
}
Vector3 myposition;
//make on touch
void Update ()
{
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch (0);
//(touch.phase == TouchPhase.Began)
Vector3 touchPosition = Camera.main.ScreenToWorldPoint (new Vector3 (touch.position.x, touch.position.y, 25));
myposition = touchPosition;
transform.position = Vector3.Lerp (transform.position, myposition, Time.deltaTime*10);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
hi everyone how can i move an object from a point to specific point(point b) by mouse click 0 Answers
Can someone give me code for random.range in the y axis? 0 Answers
Defining a starting position for a gameobject? 1 Answer
iTween islocal still using object parent axes for MoveTo 0 Answers
Path Movement created from user input.mouse and player follows it. 0 Answers