I have this code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody rb;
private bool isGrounded;
void Start ()
{
rb = GetComponent<Rigidbody> ();
isGrounded = true;
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
float jumpers = 0;
if (isGrounded)
{
if (Input.GetKeyDown (KeyCode.Space))
{
jumpers = 15.0f;
isGrounded = false;
}
}
Vector3 movement = new Vector3 (moveHorizontal, jumpers, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive (false);
}
if (other.gameObject.CompareTag ("Floor"))
{
isGrounded = true;
}
}
}
The problem is that I can only jump once. To state the obvious, all the floors are given the proper tag “Floor”. How can I fix this? Thanks.