Hello im new to unity and im making a running game. I am trying to make a function that if my character falls below Y (which is set to -6) it will wait for 3 seconds and then load the level called Main Menu. This is my script that I am using. Its from the Runner tutorial but I am doing the game over part diffrent
using UnityEngine;
public class Runner : MonoBehaviour {
public static float distanceTraveled;
public float acceleration;
public Vector3 jumpVelocity;
public float gameOverY;
private bool touchingPlatform;
void Update () {
if(touchingPlatform && Input.GetButtonDown("Jump")){
rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
touchingPlatform = false;
}
distanceTraveled = transform.localPosition.x;
if(transform.localPosition.y < gameOverY){
yield return new WaitForSeconds(3);
Application.LoadLevel("Main Menu");
}
}
void FixedUpdate () {
if(touchingPlatform){
rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration);
}
}
void OnCollisionEnter () {
touchingPlatform = true;
}
void OnCollisionExit () {
touchingPlatform = false;
}
}
Im getting some kind of problem so i hope you can help me.