Problem with a multi-jump script ( C# )
As the title says, i have a problem with a script that should allow me make a multi-jump with a JumpCount wich is going to run out after 4 jumps and recharge when i touch the ground. The script does not give any error, but i think there is something wrong directly in the script's drawing up It simply doesen't work when i apply it, my character jumps just one time.
using UnityEngine;
using System.Collections;
public class Volo : MonoBehaviour {
float jumpCount;
public Vector2 jumpForce = new Vector2(0, 300);
bool grounded;
void Update()
{
// If the character has more than 0 jumps left
if (Input. GetKeyDown("space") && jumpCount > 0)
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
jumpCount--; // Reduce the amount of jumps left by 1
}
// If the character is touching the ground
if (grounded)
{
jumpCount = 4; // Reset amount of jumps left to 4
}
}
void OnCollisionEnter(Collision col) // When the character collides with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
grounded = true;
}
}
void OnCollisionExit(Collision col) // When the character stops colliding with something
{
if(col.collider.tag == "ground") // If the object has the tag "ground"
{
grounded = false;
}
}
}
Is grounded properly resetting your jump count (which should probably be an int not a float)?
Use Debug.Log
ok, i did it, but the console does not show anything
I think you have unchecked the error fields in the console.
Open it up and make sure the three buttons are marked in the top right.
You should be seeing Debugs and also a warning about not using an f for your float jumpCount = 4;
Answer by Konomira · Oct 14, 2015 at 02:59 PM
if (Input. GetKeyDown("space") && jumpCount > 0)
there is a space after "Input." looks like a syntax error, remove the space and try it.
@$$anonymous$$onomira nope, that's not the problem, i've just tried