D
D
Demigodd2015-10-28 11:56:13
Unity
Demigodd, 2015-10-28 11:56:13

How can I make it stop after a player dies?

For example, ca87e0d6a00d4d5f93dc73d8cd62668d.png
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);
  }
}

c80cad81bc6549659a522f3567f25b1f.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Espleth, 2015-10-28
@Demigodd

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 question

Ask a Question

731 491 924 answers to any question