So I have a script that makes a player jump, and I am trying to make it so that it works for both PC and Console. Right now however, the script is not working on my controller. Here is what I have:
using UnityEngine;
using System.Collections;
public class Jump : MonoBehaviour {
private CharacterController controller;
private float verticalVelocity;
private float gravity = 20.0f;
private float jumpForce = 10f;
void Start () {
controller = GetComponent<CharacterController> ();
}
void Update () {
if (controller.isGrounded) {
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown (KeyCode.Space)) {
verticalVelocity = jumpForce;
}
}
else {
if (Input.GetButtonDown (KeyCode.JoystickButton0)) {
verticalVelocity = jumpForce;
}
else {
verticalVelocity -= gravity * Time.deltaTime;
}
}
Vector3 moveVector = new Vector3 (0, verticalVelocity, 0);
controller.Move (moveVector * Time.deltaTime);
}
}