Script to destroy object

Hi im making an android game where balls drop from the top of the screen and have to be destroyed when they reach the bottom where i have placed 3 buttons. i want the balls to be destroyed when they are behind the button, and the button is pressed. Im using this destroy script but it allows the balls to be destroyed anywhere on the screen

`#pragma strict

var speed : float = 4;
var hit = new RaycastHit();

function Update () {

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) {

var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);

    if (Physics.Raycast (ray, hit)) {



i want to upload a picture but it gives me a parsing error everytime i try.

I believe the problem is that you did not declare the hit variable with the out keyword.

if(Physics.Raycast(ray, out hit)) {