I can't get my joy stick to move my character

I’m making a game like subway surfers, but instead of swiping you use a joystick so I watched a tutorial on YouTube and I did everything correctly then I modified it to be the way I wanted it to be, but at the end of the tutorial he didn’t show you how to connect it to your character. So how do i make it move my character left and right but if the joystick is moved a little bit your character moves slow but if the joystick is at on the edge your character moves fast. Btw the joystick can only move left and right, it’s like a slider. This is the code.

`using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine;

public class Joystick : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
public Image bgImg;
public Image joystickImg;
public Vector3 inputVector;

private void Start()
    bgImg = GetComponent<Image>();
    joystickImg = transform.GetChild(0).GetComponent<Image>();


public virtual void OnDrag(PointerEventData ped)
    Vector2 pos;
    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(bgImg.rectTransform
                                                                , ped.position
                                                                , ped.pressEventCamera
                                                                , out pos))
        pos.x = (pos.x / bgImg.rectTransform.sizeDelta.x);
        pos.y = (pos.x / bgImg.rectTransform.sizeDelta.y);
        inputVector = new Vector3(pos.x * 2 + 1, pos.y * 0);
        inputVector = (inputVector.magnitude > 1.0f) ? inputVector.normalized : inputVector;

        joystickImg.rectTransform.anchoredPosition =
            new Vector3(inputVector.x * (bgImg.rectTransform.sizeDelta.x / 3.5f)
                        , inputVector.z * 0);


public virtual void OnPointerDown(PointerEventData ped)


public virtual void OnPointerUp(PointerEventData ped)
    inputVector = Vector3.zero;
    joystickImg.rectTransform.anchoredPosition = Vector3.zero;




This tutorial is useful for joy stick you can check from below link.
Link: How to create mobile joystick in Unity 2018 🎮 - YouTube
Github Link: Fixed Button / Fixed Touch Field (in addition to https://assetstore.unity.com/packages/tools/input-management/joystick-pack-107631) · GitHub