So I currently have a character that switches to its ragdoll and “dies” upon contact with a kill object, however after the ragdoll falls out of screen I need the level to restart. I’m new to C#. Just looking for a simple way to get the game to restart without player input. I’m kind of moving over from java script so I don’t have reference for how to do this.
here is how I have the character death setup. any suggestions are greatly appreciated.
using UnityEngine;
using System.Collections;
public class Entity : MonoBehaviour {
public float health;
public GameObject ragdoll;
public void TakeDamage(float dmg) {
health -= dmg;
if (health <= 0) {
Die();
}
}
public void Die() {
Ragdoll r = (Instantiate(ragdoll,transform.position,transform.rotation) as GameObject).GetComponent<Ragdoll>();
r.CopyPose(transform);
Destroy(this.gameObject);
}
}
Use the following code to restart the level:
using UnityEngine;
using System.Collections;
public class Entity : MonoBehaviour {
public float health;
public GameObject ragdoll;
public void TakeDamage(float dmg) {
health -= dmg;
if (health <= 0) {
Die();
}
}
public void Die() {
Application.LoadLevel(Application.loadedLevel);
}
}
Appreciate all the feedback.It definitely helped. I got it all to work perfectly after reading more into the documentation of coroutines.
So I have tried all kinds of different values to get it to wait. I want it to wait for 5 seconds before restarting the level.
if (other.tag == "Player")
{
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
if (time <= 6)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
time = 1;
}
gameController2.AddScore(scoreValue);
Destroy (other.gameObject);
Destroy (gameObject);
}
}
I’ve tried changing the values to if (time >= 6) then if (time >= -6) I’ve tried the negative values on both the if factor and the time factor. Can you guys catch what I am doing wrong?