Double jump. Jumping after falling off a platform

I have tried to make a double jumping feature in my game. It works fine. But. A player can jump after leaving a platform if a jump is done. If he uses double jump before he lands, he can’t jump after leaving a platform. In my game I don’t want a Player to be able to jump if he falls off a platform.

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

	public float moveSpeed;
	public float jumpForce;
	public bool grounded;
	public LayerMask whatIsGround;

	private Rigidbody2D rb;
	private Collider2D coll;
	private Animator anim;
	private bool canDoubleJump;



	void Start () 
	{
		rb = GetComponent<Rigidbody2D> ();
		coll = GetComponent<Collider2D> ();
		anim = GetComponent<Animator> ();
	}
	

	void FixedUpdate () 
	{
		grounded = Physics2D.IsTouchingLayers (coll, whatIsGround);
	}

	void Update ()
	{
		rb.velocity = new Vector2 (moveSpeed, rb.velocity.y);
		if (Input.GetButtonDown ("Fire1")) 
		{
			if (grounded) 
			{
				rb.velocity = new Vector2 (rb.velocity.x, jumpForce);
				canDoubleJump = true;

			}
				
			if (!grounded && canDoubleJump)
			{		
				rb.velocity = new Vector2 (rb.velocity.x, jumpForce);
				canDoubleJump = false;
			}
		}

		anim.SetFloat ("Speed", rb.velocity.x);
		anim.SetBool ("Grounded", grounded);
	}

	
}

My guess is to somehow reset a “canDoubleJump” after a Player lands but everything I tried didn’t work. So. I need some help. I am a begginer in scripting and Unity as you can obviously see. And my English is not that well)
Thanks!

Hello there.

OK, you can make the change when the player lands into the ground, he can jump after that, now this is the trick:

  1. If the character it has “touched” any ground layered as “environment” he can make a double jump.
  2. But, if the character it has “touched” any ground layered as “platforms” then he can’t make any jump.

So, what you already need to do it is store the layer value to make a comparison at the jump event, something like this:

if (grounded) {
    if ("The current ground equal to environment") {
        "Then he can jump and double jump";
    }
} else {
    "Here makes the character go down to ground";
}

As you can see, only, if the character is the ground established to make a jump he then can jump, but, if not, then he deserves to die (uuuuooooh! you are so bad), cheers.