Search Unity

Space SHooter

Discussion in 'Community Learning & Teaching' started by meteoros, Mar 27, 2015.

  1. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    Ending the game - 15 - Space Shooter - Unity Official Tutorials
    Hi, i'm having problems in the game over action in "destroy by contact" script (9:07m) my ship colides with asteroid,it was supose to see the text "Game Over Text" but nothing happens, any ideias how to solve it?

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DestroyByContact : MonoBehaviour
    6. {
    7.     public GameObject explosion;
    8.     public GameObject playerExplosion;
    9.     public int scoreValue;
    10.     private GameController gameController;
    11.  
    12.     void Start ()
    13.     {
    14.         GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    15.         if(gameControllerObject != null)
    16.         {
    17.             gameController = gameControllerObject.GetComponent<GameController>();
    18.         }
    19.         if (gameController == null)
    20.         {
    21.             Debug.Log ("Cannot find 'GameController' script");
    22.         }
    23.     }
    24.  
    25.     void OnTriggerEnter(Collider other)
    26.     {
    27.         if (other.tag == "Boundary")
    28.         {
    29.             return;
    30.         }
    31.         Instantiate (explosion, transform.position, transform.rotation);
    32.         if (other.tag == "Player")
    33.         {
    34.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    35.             gameController.GameOver ();      
    36.         }
    37.         gameController.AddScore (scoreValue);
    38.         Destroy (other.gameObject);
    39.         Destroy (gameObject);
    40.     }
    41. }
    42.  
     
    Last edited: Mar 27, 2015
  2. meteoros

    meteoros

    Joined:
    Mar 19, 2015
    Posts:
    15
    I just watched the video again from start and i found missing code in "GameController" script in:
    Code (csharp):
    1.  
    2. public void GameOver ()
    3.     {
    4.         gameOverText.text = "Game Over!";
    5.         gameOver = true;
    6.     }
    7.  
    this 2 lines were missing
    Code (csharp):
    1.  
    2. gameOverText.text = "Game Over!";
    3.         gameOver = true;
    4.  
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664