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.

ending game?

Discussion in 'Scripting' started by MrTsukuda, Jan 24, 2010.

  1. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    Hi, I'm new to scripting, and making games. I made my whole game, and the only thing I need done is a script to end the game when you touch an object.

    I want it to fade out, and then just exit to the desktop :)

    can anyone make one for me, or tell me where there is an easy tutorial for it? ^^
     
  2. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
  3. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    That helped me a little, but I still don't know how to make it exit to the desktop?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,334
    Application.Quit()

    --Eric
     
    miblaha likes this.
  5. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    Thanks ^^ But how do I make it happen, when I touch the object, and not just when the game starts?
     
  6. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    Please someone, i'll need to know soon... I've tried to make a script, to just make the game end, but it doesn't work... what am I doing wrong?

    ------------------------------

    var quit = true;

    function Touch()
    {
    if(quit)
    {
    Application.Quit();
    }
    }
     
  7. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Just make an on function activate, Application (Quit) and attach it to the endgame activator.
     
  8. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Just make an on function activate, Application (Quit) and attach it to the endgame activator. You will need to add a timer for the fade also.
     
  9. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    okay, I didn't really understand that... or it just didn't work... could you please copy/paste mine, and then put in the changes?
     
  10. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    Okay... can someone please just make a quick script, for closing the game, when touching a specific object? no need for fade or anything, just closing the game?
     
  11. MrTsukuda

    MrTsukuda

    Joined:
    Jan 24, 2010
    Posts:
    11
    Can't someone just please make one that makes it close when you press esc? Please, anything that makes the game close o_O
     
  12. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,853
    It sounds like you need to take a step back and learn the basics of Unity such as using triggers, input, and simple scripts.

    I would suggest to go through one of our tutorials:
    http://unity3d.com/support/resources/tutorials/

    Once you have that basic understanding, doing the things you ask about are very simple with the pointers people have already given in this thread.

    Rune
     
    DanVioletSagmiller likes this.
  13. Mirage

    Mirage

    Joined:
    Jan 13, 2010
    Posts:
    230
    Try this, this should make the game close when you press the defined key.

    Code (csharp):
    1. function Update () {
    2.     // Did the user press the quit key?
    3.     if (Input.GetButton ("INSERT QUIT KEY HERE"))
    4.         Application.Quit();
    5.     }
    Make sure you set the quit key up in the Project settings/ Input menu. Caps do matter.

    Edit: You do know that pressing Alt-F4 quits whatever application windows has open right? Use this untill you get a quit button setup.
     
  14. Gamerdad81

    Gamerdad81

    Joined:
    Jul 25, 2010
    Posts:
    23
    Take what you need from this script, but basically it lets you click on say an "exit" button and quits the game or click on a "load" or "start game" button to load a scene. Also make sure after you apply this script to your exit button object make sure to check the isQuit box in the inspector.

    var isQuitButton = false;

    function OnMouseEnter()
    {
    // CHange color of text /
    renderer.material.color = Color.red;
    }

    function OnMouseExit()
    {
    // CHange color of text /
    renderer.material.color = Color.white;
    }

    function OnMouseUp()
    {

    // are we dealing witha quit button //
    if( isQuitButton )
    {
    // quit the game //
    Application.Quit();
    }
    else
    {
    // load level //
    Application.LoadLevel(1);
    }
    }
     
  15. avidgamer

    avidgamer

    Joined:
    Aug 1, 2012
    Posts:
    8
    I think this will only work in a Build Version so you'll have to use Debug.Log() untill you build a version to test
     
  16. kurtfury

    kurtfury

    Joined:
    Oct 18, 2012
    Posts:
    4
    function OnGUI () {
    if(GUIEnabled) {
    if (GUI.Button (Rect (Screen.width / 2,Screen.height / 2 - 60,160,20), "Exit Game")) {
    Application.Quit();
    }
    }
    }
     
    Last edited: Sep 8, 2013
unityunity