Search Unity

Make Game end after 5 Deaths?

Discussion in 'Getting Started' started by MirioTogata, Nov 18, 2018.

  1. MirioTogata

    MirioTogata

    Joined:
    Oct 4, 2018
    Posts:
    7
    Hi,
    I'm making a game wiht a rollerball and want it to end after 5 deaths.
    Also I want to have the amount of deaths and tries that are left shown on screen.
    I've got some ideas how to achieve that but my coding skills are very limited (bad) so maybe someone can help me out:
    Code (CSharp):
    1.     using System.Collections;
    2.     using System.Collections.Generic;
    3.     using UnityEngine;
    4.    
    5.     public class Leben : MonoBehaviour {
    6.         public UnityEngine.UI.Text Falls;
    7.         public UnityEngine.UI.Text Lifes;
    8.    
    9.         void Start () {
    10.    
    11.         }
    12.    
    13.         void Update () {
    14.             Fall0ut = if transform.position.y < -200    
    15.                 int counter = 0;
    16.             While (counter < 5) {
    17.                 counter++;
    18.                 Debug.Log(counter);
    19.             }
    20.    
    21.             Life0ut = if transform.position.y < -200
    22.                 int counter = 5;
    23.             While (counter > 0) {
    24.                 counter--;
    25.                 Debug.Log(counter);
    26.             }
    27.    
    28.             Falls.text = Fall0ut.ToString();
    29.             Lifes.text = Life0ut.ToString();    
    30.         }
    31.     }
    32.    
    33.