How to add jump on the joystick in unity?

I have 2 scripts which are interconnected.Here is the first,which is mainly responsible for the function flip
using UnityEngine;

public class HeroController : MonoBehaviour
{
public static Animator anim;
public static float moveInput = 0;
private bool facingRight = true;

public float speedMain = 0;

Rigidbody2D rb;

void Start()
{
anim = GetComponent();
rb = GetComponent();
moveInput = 0;
}

void FixedUpdate()
{
rb.velocity = new Vector2(moveInput * speedMain, rb.velocity.y);

if (moveInput > 0 || moveInput < 0)
{
anim.SetInteger("Anim", 2);

}
else
{
anim.SetBool("run", false);
}

if (facingRight == false && moveInput > 0)
{
gameObject.GetComponent().flipX = false;
Flip();
}
else if (facingRight == true && moveInput < 0)
{
gameObject.GetComponent().flipX = true;
Flip();
}
}

public void Flip()
{
facingRight = !facingRight;
}
}

But the second which is responsible for the movement via the joystick:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cherocntrlbtn : MonoBehaviour
{
public Joystick joystick;
Rigidbody2D rb;
Vector3 position;



private void Update()
{
if (joystick.Horizontal > 0.1 f)
{
HeroController.moveInput = 1;
}
else if (joystick.Horizontal < -0.1 f)
{
HeroController.moveInput = -1;
}

else
{
HeroController.moveInput = 0;
}
}
}
Here.And for some reason I can't add my code to the Persian jumped if you move the joystick up.please help.
If suddenly you have also written a game with a joystick,please send your script.
April 4th 20 at 00:41
0 answer

Find more questions by tags Unity Game EngineGame controllers