Move my character where i touched

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 ;

#pragma strict
var amirpos : Vector3 ;
var touchpos : Vector3 ;
var parmak : Touch ;
var camerapos : Vector3 ;
var touchposcam : Vector3 ;
var speed : float = 15.0f ;
function Start () {

}

function Update () 
{
amirpos = GameObject.Find("Amirr").transform.position;
camerapos = Camera.main.gameObject.transform.position;
touchposcam = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
touchpos = Vector2 ( touchposcam.x , touchposcam.y );
if(parmak.phase == TouchPhase.Began && Input.touchCount >0)
{

if(amirpos.x != touchpos.x)
{
 transform.position = Vector3( (touchpos.x-amirpos.x)/speed , (touchpos.y-amirpos.y)/speed , camerapos.z-amirpos.z ) ;
}
}
}

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 .

Even if I am not familiar with mobile games, I would have tried as follow :

#pragma strict

// Drag & drop the Amiir GameObject here
var amiir : Transform ;

// Drag & drop the main camera here
var mainCamera : Camera ;

var speed : float = 15.0f ;

var amirpos : Vector3 ;
var touchpos : Vector3 ;
var parmak : Touch ;
var touchposcam : Vector3 ;

function Update () 
{
    if( Input.touchCount > 0 )
    {        
        touchposcam =   mainCamera.ScreenToWorldPoint(Input.GetTouch(0).position);
        touchpos =      Vector2 ( touchposcam.x , touchposcam.y );
    }
    
    amirpos = amiir.position;

    if(parmak.phase == TouchPhase.Began )
    {
        if(amirpos.x != touchpos.x)
        {
            transform.position = Vector3( (touchpos.x-amirpos.x)/speed , (touchpos.y-amirpos.y)/speed , mainCamera.transform.position.z-amirpos.z ) ;
        }
    }
}

Im not JS person. In c# This code might help

Inside the Update()

//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);

}