I’m using this script to control my character in a 2.5D side scrolling platformer with this script the character can move side to side but can’t jump. what I’m trying to do is allow the player to jump but the script cant convert the bool input from input.getkey to a float value for the vector3 so the editor comes up with the errors
"Assets/PlayeController.cs(26,75): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments"
"Assets/PlayeController.cs(26,75): error CS1503: Argument `#1' cannot convert `bool' expression to type `float'"
is there a way to make the jump bool into a float (or vice versa)
here is the code;
using UnityEngine;
using System.Collections;
public class PlayeController : MonoBehaviour {
public float speed;
public float jumpHeight;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rb.AddForce (movement * speed);
bool jump = Input.GetKey ("Jump");
Vector3 jumping = new Vector3 (0.0f, jump, 0.0f);
rb.AddForce (jumping * speed);
}
}