So I am currently working with a platformer and being new to coding I need some help with implementing double jumping into my code. I have seen others asking questions about this aswell but their codes are so different to mine that I have not been able to implement the answers found there. Heres the code I am working with(without any doublejumping failures) :
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 10, jumpVelocity = 10;
public LayerMask playerMask;
Transform myTrans, tagGround;
Rigidbody2D myBody;
public bool isGrounded = false;
void Start ()
{
myBody = this.rigidbody2D;
myTrans = this.transform;
tagGround = GameObject.Find (this.name + "/tag_ground").transform;
}
void FixedUpdate ()
{
isGrounded = Physics2D.Linecast (myTrans.position, tagGround.position, playerMask);
Move (Input.GetAxisRaw("Horizontal"));
if (Input.GetButtonDown ("Jump"))
Jump ();
}
//Moving
public void Move(float horizontalInput)
{
Vector2 moveVel = myBody.velocity;
moveVel.x = horizontalInput * speed;
myBody.velocity = moveVel;
}
//Jumping
public void Jump ()
{
if (isGrounded)
myBody.velocity += jumpVelocity * Vector2.up;
}
}