Answer the question
In order to leave comments, you need to log in
How can I make it stop after a player dies?
For example,
when it falls on the die collider, it dies and continues to fall until it respawns, and this is after 1 sec, so do it so that it does not fall?
using UnityEngine;
using System.Collections;
public class LevelManager : MonoBehaviour {
public GameObject currentCheckpoint;
private characterController Hero;
public GameObject deathParticle;
public GameObject respawnParticle;
public int pointPenaltyOnDeath;
public float respawnDelay;
private CameraController Camera;
//private float gravityStore;
//public HealthManager healthMnager;
// Use this for initialization
void Start () {
Hero = FindObjectOfType<characterController> ();
Camera = FindObjectOfType<CameraController> ();
//healthMnager = FindObjectOfType<HealthManager> ();
}
void Update () {
}
public void RespawnPlayer()
{
StartCoroutine ("RespawnPlayerCo");
}
public IEnumerator RespawnPlayerCo()
{
Instantiate (deathParticle, Hero.transform.position, Hero.transform.rotation);
Hero.enabled = false;
Hero.GetComponent<Renderer>().enabled = false;
Hero.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
ScoreManager.AddPoints (-pointPenaltyOnDeath);
Debug.Log ("Player Respawn");
yield return new WaitForSeconds (respawnDelay);
//Hero.GetComponent<Rigidbody2D> ().gravityScale = gravityStore;
Hero.transform.position = currentCheckpoint.transform.position;
Hero.enabled = true;
Hero.GetComponent<Renderer> ().enabled = true;
//healthMnager.FullHealth ();
//healthMnager.isDead = false;
Camera.isFollowing = true;
Instantiate (respawnParticle, Hero.transform.position, Hero.transform.rotation);
}
}
Answer the question
In order to leave comments, you need to log in
Hero.GetComponent().constraints = RigidbodyConstraints2D.FreezeAll;
then unfreeze when
Hero.GetComponent().constraints = RigidbodyConstraints2D.FreezeRotation;
This is if you have FreezeRotation, if not, then how to do it without freezing the rotation, I think, you can easily figure it out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question