Help me to optimize a few line of code.

Hey,

I am having a little optimization issue with one of my functions.

I am creating a game for Android. I have a button, if the player touch it, one of the game object will jump. I am using EZGUI for the GUI system.

So, if the player touch the EZGUI button, it calls a function in the GUI manager. Then than function calls the jump function on the player object. I cant put the jump function to the level manager, and can’t call the jump function directly (only through the gui manager).

The problem is, that there is a 0.3 - 0.5 second delay between the button touch, and the actual jump. This delay is enough to miss the jump.

Here is the function on the gui manager:

function JumpGUI() 
{
	marbleControls.Jump();
}

And here is the actual jump function:

function Jump()
{
	if (canJump)
	{
		canJump = false;
		rigidbody.velocity.y = jumpDistY;
		rigidbody.AddForce (rigidbody.velocity * curSpeed * jumpDistX);
		yield WaitForSeconds(0.5);
		canJump = true;
	}
}

Any advice is welcomed!

Perhaps try changing your ForceMode to Impulse instead of the Force?

rigidbody.AddForce (rigidbody.velocity * curSpeed * jumpDistX, ForceMode.Impulse);