Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Figerox · Sep 20, 2012 at 05:44 PM · triggerapplicationquit

How to make an Application.quit on trigger?

I want to make it so that when my character touches the enemy's collider, (and in the case, it would be a sphere collider,) It automatically closes the game. So far, this is what I have an it will not work. The most It did was freeze the game for a second, then resumed playing. I have the code on my Main Camera, so it will happen with all of the enemies.

 function OnControllerColliderHit(hit : ControllerColliderHit)
 {
     if (hit.collider.name == "Sphere Collider")
     {
         Application.Quit();
     }
 }

What am i doing wrong?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Khada · Sep 20, 2012 at 05:48 PM 0
Share

Oops, didn't see your comment. I'll let you answer.

avatar image AlucardJay · Sep 20, 2012 at 05:50 PM 1
Share

I wasn't sure as the OP didn't specify, but it would probably be safe to assume it is in editor.

avatar image Figerox · Sep 20, 2012 at 06:32 PM 0
Share

So sorry i didn't specify where it was! I've tried it on normal "windows" mode, Editor mode, and "Windows 64-Bit" mode. Nothing.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AlucardJay · Sep 20, 2012 at 05:45 PM

Quit is ignored in the editor or the web player.

http://docs.unity3d.com/Documentation/ScriptReference/Application.Quit.html

You need to play it in a build. For example PC and Mac Standalone :

http://docs.unity3d.com/Documentation/Manual/PublishingBuilds.html

http://docs.unity3d.com/Documentation/Components/class-PlayerSettings.html

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Figerox · Sep 20, 2012 at 06:45 PM 0
Share

Yes, I tried it on all available options just now to confirm it for myself. same thing. The game that I'm making is essentially done, besides this stupid trigger.

avatar image AlucardJay · Sep 20, 2012 at 06:56 PM 0
Share

Well maybe check backwards to see where it is breaking. First thing to do (is it switched on?) is to check the trigger event. Place a Debug.Log as the first line in your collider hit function :

 Debug.Log( "hit.collider.name = " + hit.collider.name );

does this return "Sphere Collider" ?

avatar image Figerox · Sep 20, 2012 at 07:11 PM 0
Share

Debug.Log( "hit.collider.name = " + hit.collider.name );

function OnControllerColliderHit(hit : ControllerColliderHit)

{ if (hit.collider.name == "Sphere Collider")

 {

     Application.Quit();

 }

}

Like that? If so, it says "unknown identifier: Hit"

avatar image AlucardJay · Sep 20, 2012 at 07:13 PM 0
Share

No, just above if (hit.collider ..... inside the function =]

avatar image Figerox · Sep 29, 2012 at 09:28 PM 0
Share

I still have not successfully done this.

Show more comments
avatar image
0

Answer by Kiloblargh · Sep 30, 2012 at 01:53 AM

Why are you trying to do this? It would be interpreted as a crash by the player and probably be rejected from the app store, if that was where you were trying to go with it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chellebell1689 · May 04, 2015 at 01:29 AM 0
Share

I'm wanting something like this. I'm making a demo level for a term project and I just want my collision to end the test run. I currently have:

using UnityEngine; using System.Collections;

public class PlayerEvents : $$anonymous$$onoBehaviour {

 // Use this for initialization
 void Start () 
 {

 }
 
 // Update is called once per frame
 void Update () 
 {

 }

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "EndEvent") 
     {
         Application.Quit();
     }
 }

}

But nothing happens...

avatar image
0

Answer by lex_dekker · Nov 10, 2021 at 10:16 AM

move away the void start() and the void update()

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android app not closing complete. 2 Answers

Application.quit() not working on android 5 Answers

Loading player location in a scene 2 Answers

Why does my trigger work in the editor but not in the .exe? 1 Answer

onExit, onQuit, or anything like that? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges