If-statement problem (float to bool error) - please provide an explanation

Hi

I have problem with understanding why I get an Assets/Scripts/cubeMove.cs(32,17): error CS0029: Cannot implicitly convert type float' to bool’

using UnityEngine;
using System.Collections;

public class cubeMove : MonoBehaviour {
	
	public int playerSpeed;
	
	public int playerTurnSpeed;
	
	private Transform myPlayerObject;
	
	// Use this for initialization
	void Start () {
		
		playerSpeed = 5;
		
		playerTurnSpeed = 5;
		
		myPlayerObject = transform;
		
		myPlayerObject.position = new Vector3(2,1,2);
	
	}
	
	// Update is called once per frame
	void Update () {
		
		myPlayerObject.Translate(Vector3.right * Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime);
		
		myPlayerObject.Translate(Vector3.forward * Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime);
		
		if(Input.GetAxis("Vertical"))
		{
			myPlayerObject.Rotate(Vector3.forward * playerTurnSpeed * Time.deltaTime);
		}
		
		
	
	}
}

My if-statement, where the error occurs, does the same as the one below (or is supposed to !), but they don’t get an error :

 void Update ()
    {
               
        if(Input.GetKey(KeyCode.RightArrow))
            transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
    }

Unity’s Translate Rotate tutorial

Would someone be so and explain ?

Also, should I stop using the Input Manager for movement and instead use: Input.GetKey(KeyCode.SomeKey
) ?

Input.GetKey returns a boolean while Input.GetAxis returns a float. You should check if Input.GetAxis is more than 0 in your case.
More info here: Unity - Scripting API: Input.GetAxis

Hey hey,

The function GetAxis returns a float (number) while the function GetKey returns a bool (true or false).
If you want to check if the buttons in the GetAxis are down or not you need to check if the float the function return is not 0.

Actually, Spoink is right, check if it’s not equal to zero. Something like:

if(Input.GetAxis("Vertical") != 0)

Hi guys

Thank you for helping out on a newbie distress call.

I have gotten the code to work by chekking to see if it was more than zero as told you me to @wolfhunter777 - thank you for not writting me the code in your first reply - in hindsight I became happy once I figured out how to check and see if the value was more than zero (I consider this a small victory for the noob/newbie)

I had actually thought of using the not equal to (!=), however, I wasn’t brave enough to take the plunge.

Anyway, thank you both for helping a noob in need !

thank you i was struggling so much i had no idea that get axis uses 1 or -1.

I’ve used to create input for keyboard and android :
https://hatebin.com/ukwcerasmu