Using the accelerometer for collecting

First, it’s important that you use code tags when sharing code . The code you’ve posted is difficult to read. Code tags make it much easier on us.

It’s one thing to find and explain syntax errors in code. I never mind doing that. It gets a bit more questionable with logic errors. My thinking is that if I tell you how to do it, you didn’t actually learn anything. Note that I haven’t used accelerometer myself, so it’s not like I’m withholding this information from you and waving it over your head… I’d have to look up the specifics myself to be able to say for sure, but you can do the same thing, so why would I steal that experience from you?!

Copying and pasting code, whether it’s from a tutorial or a fully-functioning script, is not a great idea. You kinda need to know what each line does and why you’re using it. That’s the only way you can get better and get yourself to the point where you can do this stuff all on your own. When you run into a line of code that you don’t understand its purpose, look it up in the API (or a C# reference if it’s not Unity-specific).

Beyond the syntax of the code you’re using, understand the logical purpose of each line. Especially when you’re combing content from two different resources as you’re doing here. So, for example, the variable “isFlat” you’re using. What is its purpose? Why is there code inside an if block checking its true status? Can it ever be false? (It doesn’t look like it from what you’ve shared).

Programming isn’t just a set of commands you string together to make things happen. It’s training your brain to work a specific way to solve problems one logical step at a time. That way of thinking isn’t natural and takes a lot of time and practice to really zero in. Don’t feel bad for not understanding it immediately. Just keep at it until it all starts to click. And it will eventually click if you stick with it.

Maybe go back through and see which parts, specifically, you don’t understand the function of. Read the appropriate pages of the API documentation and see if it makes more sense. If it doesn’t, try writing the same thing using concepts you do understand. And if you don’t know the right words to make that happen, Google how to do that very specific thing (“how to use accelerometer input in unity”, for example) and read the first 20 links you get back until you get the idea. I’ve only been programming for about 6.5 years now, but I’m pretty good. And yet I still have to look stuff up almost every single day. It’s a lifelong journey!