Script has no errors, but still doesn't work!

Hey,

I’ve got this script made, but when I try it on my dad’s android tablet, it won’t work. Can you guys help me please? I really need it fixed!
Hope for your help. Thanks.

var PingGood: AudioClip;

function OnTouch(){
           
             audio.PlayOneShot(PingGood);

            yield WaitForSeconds(0.6);

            Destroy (gameObject);

            ScoreBoard.SCORE = ScoreBoard.SCORE + 100;

        }

So When I touch the object the script is attached to, it plays the sound, waits till it’s finished, and then destroys the object the script is attached to and adds score to the score system.
Hope for your help!

Can you show the code that calls OnTouch?

Is OnTouch a real event handler? If so, it’s a stupid one. Use Input.touches and Camera.main.ScreenPointToRay.

Maybe becouse you trying add score after gameObject has destroyed?

Well can you change the script for me, or help me doing that? I also want to learn from it.

No it’s not that, because it works when u use input.getbuttondown or something like that, but when i try to convert it to touch, it won’t work!

Hope you guys can help me :smile:

Attach the code file so we can have a look.

Ok I get so confused I spit the forum out for hours and nothing work, just need to touch an object and do this.

So here something that detect the touch on one single object, and does the script only on the object that’s touched.

and here the code I use on the object the script contains:

 audio.PlayOneShot(PingGood);

    Destroy (gameObject);

    ScoreBoard.SCORE = (ScoreBoard.SCORE + 100)

And what do you mean with the code file? Thanks for your help so far!