how to write code well?

I am a beginner.I can understand the code other person write,but I don't know how to begin when I want to write some code. Especially some Complex code. cananybody give me some advice.thank you!

You should probably start reading the tutorials mentioned in this answer:

How can I start learning Unity fast? ( List Of Tutorials )

There are a mixture of topics - both learning programming and learning to use the Unity IDE, so pick and choose which of them feels most suitable for you!

I guess that doesn't matter. I think you just should write the code your way, and remember comments, so you always can change the code later.

Actually, I started scripting in Unity 3 weeks ago, and after one week, I was surprised that its not that complicated at all. I started like you once. I just opened a script/code someone else written, and then I just looked at it, write my own code after.

But i'm not a good code writer yet, so maybe im not right, but you should definitely look at scripts and make your own little scripts or follow some tutorials.

I never write a line Code before comming to Unity. Reading a book about Object-oriented programming, and working with Unity Tutorials helped me most to understand.