As i wrote in the title i need with ground detection. I want to make it so that only can jump once and i know that you can use ground checking or raycast and i have tried both but i couldn´t get it to work.
My movement code*:*
public class Boll_kontrollLVL3 : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public float jumpSpeed = 100.0f;
private Rigidbody rb;
private int count;
float movementSpeed;
void Update()
{
float amountToMove = movementSpeed * Time.deltaTime;
Vector3 movement = (Input.GetAxis ("Horizontal") * -Vector3.left * amountToMove) + (Input.GetAxis ("Vertical") * Vector3.forward * amountToMove);
rb.AddForce (movement, ForceMode.Force);
if (Input.GetKeyDown ("space")) {
rb.AddForce (Vector3.up * jumpSpeed);
}
}
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up")) {
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Cubes Collected: " + count.ToString ();
if (count >= 12) {
winText.text = "Level cleared!";
}
if (count >= 12) {
Application.LoadLevel ("Roll a Ball 04");
}
}
}