- Home /
Procedural/Random Generation of Solar systems
I'm new to Unity,
My team and I are having some issues establishing a framework for random generation of solar systems. We currently have orbit scripts and use parenting. We basically parent each planet to a star that is a point light with a flare.
What I really need to know is....
If I have all the other scripts which I need to apply to general objects which will be generated, how can I have the main generation script apply those scripts to the generated objects?
For instance, I generate a sun and planets. The planets need to be children of that sun and each needs our orbit script applied to it with settings the are based on its distance from the sun. Same for moons, except they are children of their planet.
Also, Any experienced coders here that want to help with this project are welcome to join the team after I see examples of your work.
What language are you coding in? This isn't a recruitment site- go to the forums for that stuff.
I'm not really recruiting, that was just an extra tid bit.
C# btw... and thanks!
Answer by syclamoth · Mar 12, 2012 at 08:02 AM
If you want to add a script to a newly created gameObject, use this:
NameOfComponent newComponent = newObject.AddComponent<NameOfComponent>();
Then, use some kind of initialisation method if you need to pass specific information to the newly instantiated component.
So say I have a planet which I want to add the Planet_orbit script to, and the planet is named automatically by its position in the star system.
Also, all Planets have a Planet tag and are in the Planet layer. Is there a way I can apply something to all objects within a layer or with a specific tag?
(Planet Rigel-2 would be a good example.)
Now could you write a specific reference in C#, ins$$anonymous$$d of Java?
We don't use java much, I prefer to keep all our code in C#.
That was C# code. Unity doesn't use Java, it uses C#, Unityscript A$$anonymous$$A Javascript, and Boo.
You can use this function to find all planets in the scene: http://unity3d.com/support/documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html
Thanks, Eric. @$$anonymous$$dax- I always code in C# personally, so unless specified otherwise in the question, that's the language my answers will be in. If that were UnityScript, it would look like this:
var newComponent : NameOfComponent = newObject.AddComponent.<NameOfComponent>();
See, that's very different.
Also, when I say Java I mean JS (JavaScript), I know that's not exacting but they both have Java in or as their name.
Java is not interchangeable with Javascript; they are different languages. Using them to mean the same thing is like saying $$anonymous$$ and $$anonymous$$r gas are the same because they start with the same few letters.
Answer by tucano · Apr 27, 2012 at 02:12 AM
I am working on a library to generate pseudo random numbers in Unity. May be you are interested in use it/contribute to it: