Hi there,
I have a script spawning my player at the beginning of the game.
When my player dies ( when falling from more than 8 meters ).
My respawn is not working.
Any idea to help me ?
Thank you…
Here is my script:
public class DeathRecognition : MonoBehaviour
{
public Transform spawnPoint;
public bool falling = false;
public float lastY; // last grounded height
public float hauteurChute; // ce ki cause ma mort
public CharacterController character; // sera eventuellement detruit
private float deathFall = 7.632f; // pour etre constant de mon 8 m de map...
// lavatar glisse un peu sur les parois (+/- 0.30)
void spawn()
{
transform.position = spawnPoint.position;
}
void Start()
{
spawn();
}
void Update()
{
if (character.isGrounded == false) // est en train de tomber sans avoir saute
{
hauteurChute = lastY - transform.position.y ;
if (hauteurChute < 0) lastY = this.transform.position.y; // si je suis en train de sauter
// la valeur la + haute de mon saut
}
else
{
if ( hauteurChute > 0.5 )
{
Debug.Log("Hauteur du saut :"+ hauteurChute); // hauteur de mon saut
}
if ( hauteurChute >= deathFall )
{
Debug.Log("DEAD");
Die();
}
hauteurChute = 0.0f; // si ma chute n<est pas mortelle
lastY = this.transform.position.y; // je reinitialise ma chute a 0
}
}
void Die()
{
Destroy(gameObject);
spawn();
}
}