Here is my script to move ball forward and jump on touch but ball start moving when game start, I want to move ball after touch the screen and stop the ball from moving after hits Goal (delay by 0.5 seconds)
public class PlayerController : MonoBehaviour
{
public float jump = 5f;
public float moveSpeed = 3.5f;
public Rigidbody rb;
public bool cubeIsOnTheGround = true;
void Awake()
{
startPos = transform.position;
}
private void Start()
{
rb = GetComponent<Rigidbody>();
}
public void FixedUpdate()
{
rb.MovePosition(transform.position + Vector3.forward * moveSpeed * Time.fixedDeltaTime);
}
void Update()
{
if(Input.GetMouseButtonDown(0) && cubeIsOnTheGround)
{
rb.AddForce(new Vector3(0, jump, 0), ForceMode.Impulse);
cubeIsOnTheGround = false;
}
}