Amazing what a few extra hours of sleep can do. I worked out why it wasn’t working. I don’t need to be a coding genius it just has to work and in this case I simple script out to different objects (which I fixed and now collisions work easier) and by detecting z coordinates it’ll see if the pipes are hit with the ammo/draino. So now if I put an IF statement in there I can tell which pipe was hit… it might be easier long term to have a whole scoring system in a separate script though. This I can reference later and build on. This script has to (a) detect when the draino hit a pipe (b) increase that pipes value by 1 (c) show that it hit the pipe through UI (d) once the pipe is “full” hitting it again will not trigger anything (except maybe bounce back slightly into the water) (e) once all pipes are full game is won. Maybe instead of putting the onus on the projectile I can put it on the pipes. It might be easier in structure than a ton of nesting IF statements. onCollisionEnter and onTriggerEnter are painfully similar things – as far as I can tell triggers require the trigger box to be ticked (in the objects Rigidbody) while collision objects do not. With triggers other objects (with Rigidbodies) can pass through unaffected while they will react in any way with other objects (bounce off etc) even if no specific scripting exists for that actual interaction.
- For OnTriggerEnter(Collider other) voids → If you use “Destroy(gameObject);” on an object it will detonate itself. If you use “Destroy(other.gameObject);” it will slay anything that touches it 🙂
- By using a While loop with void (instead of inside a IEnumerator) I froze my Unity program completely (though it left my computer fully functional). It sucked up over 20gb of memory (according to the Task Manager) trying to complete that request 😄 Luckily (?) I recently kitted out my laptop to 64Gb of RAM (up from 32) so it laughed at Unity trying it’s best to tank it.
- I’m making another big jump by moving all my Spawning from the Spawn Manager to the Game Manager and learning a new way to do it… gah! Just when I have one under my belt a new one comes up. Before I do that – I’m fairly sure all I need is a way to access external scripts and share a single variable and I may not need to do this…
- Finally. I was able to share Game Over between scripts. God that took ages. Hopefully this means I’ll be able to retrieve components faster in the future. Finally I was able to use an IF statement to stop spawning. God this was easier now than I thought it was. I’ll self destruct all items once Game Over. Nope – I know it would be easy… And it was! Next step is programming UI over the pipes. I also want to limit the shots to 10 (reduce by one each time) per ammo recharge, a title screen, and a restart button. Stretch goals = sound effects, music, button to turn these on and off (in title screen), and even another level after this one (but I think I’d rather move on to a new game instead).
- Just finishing this one game will show that I can take a project form beginning to end (shippable), give me the C# cert from Unity (unless it expires then no thank you), give me a portfolio piece (well, not a very good one but it will exist), and allow me to move on to hand-tracking etc with the confidence that I can code-dive if/when I need to. Wow, my ears hurt – I had my ear poppers in for over an hour and didn’t notice I was concentrating that hard- it’s almost 1am; time to give poor Yuka a chance to sleep.