I am trying to implement a script to destroy a gameobject when it is touched. I have the code (as below) but am unable to get it working - nothing seems to happen when i touch the gameobject. I looked through the earlier related posts in the forum and am not able to spot whats missing in my script. I have attached this script to the gameobject. Any pointers would be of great help - am I missing something obvious? Thanks very much.
function Update ()
{
var hit:RaycastHit;
for ( var evt : iPhoneTouch in iPhoneInput.touches )
{
if( evt.phase == iPhoneTouchPhase.Began )
{
var ray = Camera.main.ScreenPointToRay(evt.position);
I stuck your code in a test project I had open and it worked fine. I removed the animation line though because I was messing with primitives that don’t have animation. So the animation may be part of your problem. Maybe the Destroy call can’t be made on a GameObject while it’s playing an animation? I dunno.
Try remarking out you animation call and see what happens.
Thanks, I tried it on a cube gameobject (removed the aimation) and I could not get it to work either. Do I have to set up a few other components etc as well?
Odd. I’ve attached the test project I used, maybe that will help. I used Delete with no time argument. I figure you’re die animaiton was five seconds and that’s why the original code had a 5 arg. I had no animation, and didn’t like waiting, so I took it out.