On line (30,20) Cannot implicitly convert type 'bool' to 'float' I dont Understand how to fix this.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour
{

private Rigidbody2D rb2D;

private float moveSpeed;
private float jumpForce;
private bool isJumping;
float moveHorizontal;
float getKeyUp; 

// Start is called before the first frame update
void Start()
{
    rb2D = gameObject.GetComponent<Rigidbody2D>();

    moveSpeed = 3f;
    jumpForce = 60f;
    isJumping = false;
}

// Update is called once per frame
void Update()
{
    moveHorizontal = Input.GetAxisRaw("Horizontal");
    getKeyUp = Input.GetKeyUp("Space");
}

void FixedUpdate()
{
    if(moveHorizontal > 0.1f || moveHorizontal < -0.1f)
    {
        rb2D.AddForce(new Vector2(moveHorizontal * moveSpeed, 0f), ForceMode2D.Impulse);
    }

    if (!isJumping && getKeyUp > 0.1f)
    {
        rb2D.AddForce(new Vector2(0f, getKeyUp * jumpForce), ForceMode2D.Impulse);
    }
}

void OnTriggerEnter2D(Collider2D collision)
{
    if(collision.gameObject.tag == "Platform")
    {
        isJumping = false;
    }
}
void OnTriggerExit2D(Collider2D collision)
{
    if (collision.gameObject.tag == "Platform")
    {
        isJumping = true;
    }
}

}

@Khada Please Help

Hi!

The problem line is this one:

getKeyUp = Input.GetKeyUp("Space");

The compiler is confused because Input.GetKey() will return a bool - which is either true or false (because either the space key is pressed, or it isn’t) - and it doesn’t know how you want to assign that to a number (should true/false be 1/0? 0/1? 1/-1? Something else?)

You could try something like this instead if you want the input in the form of a number:

if (Input.GetKeyUp("Space"))
{
    getKeyUp = 1;
}
else
{
    getKeyUp = 0;
}

I believe there also happens to be a jump axis is the input manager which should be exactly what you’re looking for:

getKeyUp = Input.GetAxisRaw("Jump");

Hope this helps!