The first one is way more complex so I can’t help you if it’s that you’re trying to achieve ( re reading the notice and copy pasting in your project to figure it out is an option )
If you’re okay settling for a simpler code then I can share you the one I used in my game as exemple. Copy paste the same code into your game to try and then adapt it for your storie (I’ll add it in a second reply )