Touchscreen Movement??
Hello, im sorry if i do anything wrong, but i need help. Im not very new to programming, but I can't find or create a C# script for touchscreen Movement. I want to move my player sideways (position.x) with my finger and mouse.
Answer by goutham12 · Sep 26, 2017 at 06:09 AM
vector3 _target;
void Update() {
      if (input.GetMouseButtonDonw(0))
      {
          _target = Camera.ScreenToWorldPoint(Input.mousePosition);
          _target.z = transform.position.z;
        _target.y = transform.position.y;
            transform.position = _target;
      }
 
               }
Thank you i neded to change it to: _target = Camera.main.ScreenToWorldPoint(Inut.mousePosition); to make it work, but you helped a lot many thanks! But is it posibbble if i move the character when sliding my figner not only when i tap or click?
it will work.
but you have to calculate offset also for perfection. like
bool drag;
vector3 offset;
void Update(){
if (input.Get$$anonymous$$ouseButtonDonw(0))
   {
 
                  drag = true;
offset = transform.position - Camera.ScreenToWorldPoint(Input.mousePosition);
}
if (input.Get$$anonymous$$ouseButtonUp(0))
   {
 
                  drag = false;
}
if(drag){
_target = Camera.ScreenToWorldPoint(Input.mousePosition) + offset;
       _target.z = transform.position.z;
     _target.y = transform.position.y;
         transform.position = _target;
 
                  }
}
if it helps you accept it
Your answer