I had problems taking position of my touchplace , i’m getting Index out of bounds error and i cant get any movements , i’m new , help me please. Here’s the script ;
This code contains a lot of mistakes , i just added it for you to see what exactly i need . The object amirr needs to move the place where i touch and i need a script for it .
//when you tap your screen each touch will go through this loop
foreach (var touch in Input.touches) {
var myTouchPosition = touch.position //this gives your touch position
yourGameObject.transform.position = myTouchPosition; //make sense?
}
yourGameObject = game object that you
want to position
myTouchPosition = where you touch on
the screen
Updated
Smooth transaction between touch position and game object’s position
//this store your touch position
Vector3 _touchPosition;
//time
float _time = 0;
void Update(){
foreach (var touch in Input.touches) {
//get users touch position
var _touchPosition = touch.position;
//reset the time
_time = 0;
}
_time += Time.deltaTime;
//smoothly transform your game object to _touchPosition
yourGameObject.transform.position = Vector3.Lerp(yourGameObject.transform.position, _touchPosition, _time);
}