I am trying to move a gameObject by touch.
#pragma strict
var player : GameObject;
var moveToPos : Vector3;
var touchPos : Vector3;
var myTransform : Transform;
var moveSpeed : int;
function start ()
{
myTransform = transform;
}
function Update ()
{
touchPos = Input.mousePosition;
player.transform.position.z = 5;
if (Input.GetMouseButton(0)) {
moveToPos = Vector3 (touchPos.x , myTransform.position.y , 5);
myTransform.Translate(moveToPos * moveSpeed * Time.deltaTime);
Debug.Log(touchPos);
}
}
But no matter where I touch the object zooms to the right. I have asked someone with more experienced than me in unity and he has no idea why it isn’t working. I also noticed that i had to set all the variable’s values manually in the inspector.