# Touchscreen scripting help

**URL:** https://discussions.unity.com/t/touchscreen-scripting-help/498832
**Category:** Scripting
**Tags:** Scripting
**Created:** [March 2, 2013, 10:06am UTC](https://discussions.unity.com/t/touchscreen-scripting-help/498832 "2013-03-02T10:06:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ZIN](https://avatars.discourse-cdn.com/v4/letter/z/c2a13f/32.png) [@ZIN](https://discussions.unity.com/u/ZIN)
#### Post date: [March 2, 2013, 10:06am UTC](https://discussions.unity.com/t/touchscreen-scripting-help/498832/1 "2013-03-02T10:06:38Z")

</div>

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 😵‍💫

---

<div class="post-metadata">

### Author: ![TheRaider](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/theraider/32/268520_2.png) [@TheRaider](https://discussions.unity.com/u/TheRaider)
#### Post date: [March 2, 2013, 10:35am UTC](https://discussions.unity.com/t/touchscreen-scripting-help/498832/2 "2013-03-02T10:35:29Z")

</div>

```auto
	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
      		
       	  	
        }
    }

```

---

<div class="post-metadata">

### Author: ![ZIN](https://avatars.discourse-cdn.com/v4/letter/z/c2a13f/32.png) [@ZIN](https://discussions.unity.com/u/ZIN)
#### Post date: [March 2, 2013, 8:43pm UTC](https://discussions.unity.com/t/touchscreen-scripting-help/498832/3 "2013-03-02T20:43:49Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![TheRaider](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/theraider/32/268520_2.png) [@TheRaider](https://discussions.unity.com/u/TheRaider)
#### Post date: [March 2, 2013, 9:14pm UTC](https://discussions.unity.com/t/touchscreen-scripting-help/498832/4 "2013-03-02T21:14:42Z")

</div>

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.
