Avoiding Copy paste

I have a couple of scripts that for example making a planet orbit a sun. The thing is that I have more then just one planet. At this point I am just copy pasting the piece of code that creates the orbiting and change some variables like the “GameObject.Find(”…“)” so the code takes a different planet. My question now is, how can I avoid copy pasting the code? So I would for example have a bunch of different variables for different objects but they basically all go through the same lines of code or calculations.

Any help is greatly appreciated, since copy pasting this stuff with more then 10 planets starts to look ridiculous and unreadable!

Mmm, either I did not get it or you did not get the point of public variable in Unity.

Take one script, make the variable you want to modify public. They will show in the Inspector, then add the script to any object and give the value in the inspector. you will see that each object behave differently even though they have the same script.

Or you can make a top class for basic behaviour and have inheriting class for specific behaviour based on the basic behaviours.

You may have an elliptic path around a main object behaviour for all objects(earth rotates around the sun, moon rotates around the earth), this goes in the top class , but for instance planets also rotate on themselves while satellites do not this goes in the inheriting class.

Or I did not get what you meant…