UI Button Double jump
Hello Unity community, i'm trying to make the tutorial of N3K EN(Youtube) 2D game, for mobile phone's and I'm using UI Buttons. I've created an UI Button to make the jump possible but i can jump infinitely. My question : How can i give it a limit ? So that it jumps twice and not more then that for a couple of seconds ?
Here is my code ----------------
using UnityEngine; using System.Collections;
public class Test : MonoBehaviour {
public bool jumpMove;
public Vector3 zwaartekracht;
private float gravity = 1;
private float verticalVelocity; // y as snelheid movement
public CharacterController controller;
void Start () {
controller = GetComponent<CharacterController> ();
}
void Update () {
zwaartekracht = new Vector3 (0, verticalVelocity, 0);
controller.Move((zwaartekracht)*Time.deltaTime); // gravity
////////////////////////////////////////////////////////////////////////
if (controller.isGrounded) {
Jump ();
verticalVelocity = 0;
} else {
verticalVelocity -= gravity;
}
/////////////////////////////////////////////////////////////////////////
public void Jump (){
if (onClick) {
verticalVelocity = 15;
}
}
}
I'm kind of a newbie so I'm fairly proud this worked out in general. Thanks in advance!
Eeyy i have a error with the if statement
"if (onClick)"
you have a sollution maybe?