Touchscreen scripting help

Hi everyone,

I’m trying desperately to get 2 game objects to act as buttons in an app menu but even with the reference material I have found I can’t seem to find or understand a simple touch the screen to press a button example. I know it is using raycasting.

One button it to load a level which is the main app
The other is weblink.

If anyone can help that would be fantastic.

Until then I will just write and test until I hopefully figure it out :face_with_spiral_eyes:

	if (Input.GetMouseButtonDown(0))
    {
        //empty RaycastHit object which raycast puts the hit details into
        var hit : RaycastHit;
        //ray shooting out of the camera from where the mouse is
        var ray : Ray = cameraInterface.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, hit))
        {
			//check hit against name, tag, or however you are checking
      		
       	  	
        }
    }

I apologise i’m still a programming newbie.

I’m getting BCE0005 errors over Unknown Identifiers for (LevelData, cameraInterface) so my guess is that I was supposed to identify them before hand.

I’m doing something wrong I just don’t know where.

The levelData part wasn’t needed, i took it from my code. I had that there to make sure the game could only play at certain times.

at the top of the script you will need to define a camera like var cameraInterface : Camera; and then attach it in the editor.

This script isn’t finished, you need to do //check hit against name, tag, or however you are checking <— that part I just gave the raytrace code.