- Home /
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)) { Destroy(hit.transform.gameObject); } } }
i want to upload a picture but it gives me a parsing error everytime i try.
Answer by Deign · May 19, 2014 at 06:17 AM
I believe the problem is that you did not declare the hit variable with the out keyword.
if(Physics.Raycast(ray, out hit)) {
Your answer
Follow this Question
Related Questions
how can i destroy a cube when i press a gui button??? 1 Answer
Destroyable Box 1 Answer
nGUI how to deactivate UICheckbox by script? 1 Answer
Please help me debugging a script! 0 Answers