4X Space Game Tidy Up 1 (between parts 5 and 6)
Hi guys, this post isn’t a tutorial. As promised in Part 5 I have tidied things up a bit in the code.
Scripts Before Part 6 (Paste Bin – P006_PositionMath, P006_SpaceObjects, Galaxy_BeforePart6 and SolarSystem_BeforePart6)
scripts_before_part_6 (zip file)
- I have added two new scripts called SpaceObjects and PositionMath. To add them to the project download them and add them to the assets\scripts folder (be sure to rename them to get rid of the “_BeginningOfPart6” part of the name otherwise they will not work).
- PositionMath contains several methods used to calculate the position of our objects. The RandomPosition method in the Galaxy script has been moved here. So to has the code in the SolarSystem script which positioned our planets (I have created a new method which does this called PlanetPosition).
- SpaceObjects contains the code to create the sphere objects for our stars and planets. This replaces the CreateSphereObject methods in both the Galaxy and SolarSystem scripts. Instead of being passed a star or planet the method is now passed a string for the object name.
- All the code in the Galaxy and SolarSystem scripts has been updated to reflect the change in location of some of the methods.
If you have any specific questions on the changes or any trouble implementing the changes in the project let me know in the comments and I will help you out :).
I will put a small example of how we use the new scripts in part 6. It will show how we change the code which creates the star sphere object in the centre of our solar system (in the SolarSystem script). If you would like to have a go at doing this yourself before the next tutorial, go for it!