The title says it all, i only want my character to be able to Jump if he is Touching the ground
and i don’t know where to start i’m pretty new to Unity and C# and if you guys could help that would be great!
Here is the Runner Code
using UnityEngine;
using System.Collections;
public class Running : MonoBehaviour {
public static float distanceTravled;
public float acceleration;
public Score score;
private float seconds = 1;
Animator animator;
public bool dead = false;
float deathCooldown;
public Vector3 jumpVelocity;
// used to get animations
void Start () {
animator = transform.GetComponentInChildren<Animator>();
if (animator == null) {
Debug.LogError ("Didn't find animator!");
}
}
// Update is called once per frame
void Update () {
if (dead) {
seconds -= 1 * Time.deltaTime;
if (seconds <= 0) {
Application.LoadLevel ("DeathScene");
}
} else {
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown (0)) {
rigidbody2D.AddForce (Vector3.up * 185);
//Jump animation
animator.SetTrigger ("DoJump");
}
}
}
void FixedUpdate() {
if (dead)
return;
//Run Speed
transform.Translate (4.2f * Time.deltaTime, 0f, 0f);
}
//Collider to die
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag == "Obstacle") {
animator.SetTrigger ("Death");
dead = true;
audio.Play();
}
if (collision.collider.tag == "ObstacleBag") {
animator.SetTrigger("Death");
dead = true;
audio.Play();
}
if (collision.collider.tag == "ObstacleGarbage") {
animator.SetTrigger("Death");
dead = true;
audio.Play();
}
}
}
And that is the code thanks for the help in advance!