- Home /
Touch a box collider, quit the game. (2D)
Making a 2D game and am about done. One of the last things I have to do is make the "Quit" button on the main menu functional. I have a text mesh with a box collider around it (like all my other menu buttons) and when I touch it, I need it to exit the game back to Android OS. I use the same script for my menu buttons just tried to change the output to "Application.Quit();" but it doesn't work. Any help is much appreciated. C# please too.. Here is my code..
using UnityEngine;
using System.Collections;
public class Quit : MonoBehaviour {
void Start () {
}
void Update()
{
if (Input.touchCount == 1)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(touchPos)){
Application.Quit();
}
}
}
}
Answer by Sisso · Jul 14, 2014 at 04:18 PM
Application.Quit didn't work in editor, you must test it into a build.
To test in editor, simply add a debug log just before Application.Quit verify.
Last but not least, you can't have a exit button and IOS (and is not a good practice in android too).
https://developer.apple.com/library/ios/qa/qa1561/_index.html
Q: How do I programmatically quit my iOS application?
A: There is no API provided for gracefully terminating an iOS application.