I am trying to make a sort of momentum based platformer where you cant change direction or move in the air as a mobile game,
I am not the best at C# so forgive me if this is a stupid question,
I am using buttons from the canvas as my input, and I want my player to keep moving as long as the buttons are held down but I seem to have to keep tapping to make the player to move
enter code here using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
private float moveSpeed;
private float jumpSpeed;
public bool onGround = true;
private Rigidbody2D playerRb;
// Start is called before the first frame update
void Start()
{
moveSpeed = 100;
jumpSpeed = 3;
playerRb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
}
void onCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Level")
{
onGround = true;
}
}
public void MoveLeft()
{
if (onGround)
{
playerRb.AddForce(new Vector2(-moveSpeed, 0), ForceMode2D.Force);
}
}
public void MoveRight()
{
if (onGround)
{
playerRb.AddForce(new Vector2(moveSpeed, 0), ForceMode2D.Force);
}
}
}
as you can see I have created 2 different functions for my button to activate when they are clicked
Is there anyway that I can make it so these function will keep going as long as the button is pressed down?