Hello,
I have wrote a small 2d game that used Canvas.
I added 3 image components to Canvas (called UIContainer) as below image:
Then I added CSharp script (TouchDuckPlayAudio) to main_img to play an audio when touch event occurs. But when I touch anywhere on Scene, the audio also run. I expected this audio only run when I touch on main_img.
I googled and knew that should use Events System and Raycasters to detect and process touch event on child components in Canvas. But these references are not clear for me, there are some questions I hope you can help me:
- I should add scripts to Canvas (UIContainer) instead to main_img, right ?
- Could you give me small tutorial / example about touch event with Events System and Raycasters (someone shows touch event on Button in Canvas, but I think it is different with my case - I used image component) ?
Thank you very much,