Search Unity

Cannot convert "void" to "float"

Discussion in 'Scripting' started by Plyd823, Nov 21, 2017.

  1. Plyd823

    Plyd823

    Joined:
    Jun 21, 2014
    Posts:
    2
    Cannot convert void to float.(27, 17): error CS0029
    Code (CSharp):
    1. public class PlayerController : MonoBehaviour {
    2.  
    3.     public float PlayerSpeed;
    4.     public float PlayerJumpHeight;
    5.  
    6.     private float rotation;
    7.  
    8.     public int PlayerHealth;
    9.  
    10.     public bool IsFalling = true;
    11.  
    12.     private Rigidbody rb;
    13.  
    14.     // Use this for initialization
    15.     void Start ()
    16.     {
    17.         rb = GetComponent<Rigidbody> ();
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update ()
    22.     {
    23.         rotation = rb.AddForce (new Vector3(Input.GetAxis("Horizontal"),0,0) * PlayerSpeed);
    24.         rotation *= Time.deltaTime;
    25.         rb.AddRelativeTorque (Vector3.back * rotation);
    26.  
    27.         if (Input.GetKeyDown(KeyCode.UpArrow) && IsFalling == false)
    28.         {
    29.             rb.velocity = new Vector3 (0, PlayerJumpHeight, 0);
    30.         }
    31.     }
    32.  
    )
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  3. Plyd823

    Plyd823

    Joined:
    Jun 21, 2014
    Posts:
    2