Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Easiest way to end a game ontrigger

Discussion in 'Scripting' started by MIST0, Aug 5, 2014.

  1. MIST0

    MIST0

    Joined:
    Apr 26, 2014
    Posts:
    53
    Am just looking to end the game, or pause it in some way ontrigger

    Code (CSharp):
    1. if (other.gameObject.tag == "Player") {
    2.                         endText.text = "Final Score " + score;
     
  2. smitchell

    smitchell

    Joined:
    Mar 12, 2012
    Posts:
    702
    You could set the time scale to 0 to make it pause:
    http://docs.unity3d.com/ScriptReference/Time-timeScale.html

    or depending on how your game is set up just have a bool for if the game is paused, If it's not paused then run logic.

    like:
    Code (CSharp):
    1. (pseudo code)
    2.  
    3. void Update {
    4. if(!paused) {
    5. //Run Game Logic
    6. }
    7. }
     
    MIST0 likes this.
  3. MIST0

    MIST0

    Joined:
    Apr 26, 2014
    Posts:
    53
    Excellent! done it thanks.