- Home /
Menu on Android Application
I want to make a menu for my android app, but the code I am using doesn't work. I get no errors, but on tapping the plane, nothing happens.
You should imagine more as we do. Then maybe you can get the code working and tapping on the plane works.
using UnityEngine;
using System.Collections;
public class $$anonymous$$enu : $$anonymous$$onoBehaviour {
void Update () {
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position );
RaycastHit hit;
if ( Physics.Raycast(ray, out hit) && hit.transform.gameObject.name == "Play")
{
Application.LoadLevel(1);
}
}
}
}
If it's a menu you shouldn't really need to have it check for the touch count etc should you? I am not sure if it provides any better performance or is more accurate but this is pretty much what I use.
if (Input.Get$$anonymous$$ouseButtonDown(0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if(hit.transform.name == gameOverObjects[2].name)
{
}
}
}
I had a similar problem and it turned out that my object had no collider component.
Answer by DiebeImDunkeln · Jun 10, 2015 at 02:01 PM
I think it will be easier for you if you use a Canvas UI element and UI Buttons.
Then just drag the script with your function on your button On Click() event field and choose the wanted function.
Your answer
Follow this Question
Related Questions
QR with Zxing and Vuforia 1 Answer
Open Unity App using another Unity App 2 Answers
Unity 5.3 How to load current level 3 Answers
Teleport to next scene on trigger 1 Answer
Proper way for Quit Application 2 Answers