Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

error CS0029: Cannot implicitly convert type `float' to `bool'

Discussion in 'Scripting' started by hammy2747, Apr 29, 2015.

  1. hammy2747

    hammy2747

    Joined:
    Apr 19, 2014
    Posts:
    19
    Hi guys, I am pretty new to unity, so any help would be great. This is my player controller script, and I want my character to jump by using the movement.y
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public float speed = 8;
    7.     public float cameraSpeed = 3.5f;
    8.     public float jumpHeight = 2;
    9.    
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.        
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void Update () {
    18.  
    19.         //Roatation
    20.         float rotLeftRight = Input.GetAxis ("Mouse X") * cameraSpeed;
    21.         transform.Rotate (0, rotLeftRight, 0);
    22.  
    23.         float rotUpDown = Input.GetAxis ("Mouse Y") * cameraSpeed * -1;
    24.         Camera.main.transform.Rotate (rotUpDown, 0, 0);
    25.  
    26.  
    27.         //Movement
    28.         float verticalSpeed = Input.GetAxis ("Vertical") * speed;
    29.         float horizontalSpeed = Input.GetAxis ("Horizontal") * speed;
    30.  
    31.         Vector3 movement = new Vector3 (horizontalSpeed, 0f, verticalSpeed);
    32.  
    33.         movement = transform.rotation * movement;
    34.  
    35.         CharacterController cc = GetComponent<CharacterController> ();
    36.         cc.SimpleMove (movement);
    37.  
    38.  
    39.         //Jumping
    40.         if (cc.isGrounded)
    41.         {
    42.             if (Input.GetAxis ("Jump"))
    43.                 movement.y = jumpHeight;
    44.         }
    45.         cc.Move (movement * Time.deltaTime);
    46.     }
    47. }
    48.  
    I keep getting the error:
    error CS0029: Cannot implicitly convert type `float' to `bool'

    Thanks in advance
     
  2. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    I assume the error is on line 42 of your posting ?
    Code (CSharp):
    1.  if(GetAxis("Jump"))
    this method returns a float, not a bool.
    Do a search for
    Input.GetAxis ("Jump")
    for some options
     
    chelnok, hammy2747 and Kiwasi like this.
  3. hammy2747

    hammy2747

    Joined:
    Apr 19, 2014
    Posts:
    19
    Ok, thanks.
     
    Rsrc10 likes this.