Hello!
I make a game where planets generate automaticly. There is a problem that sometimes they generate touching an other one.
How can I destroy the previous planet if a new one instantiate on it? Like removing the old for the new planet. Thanks!
I use a prefab for the planet
You could try something like this:
// in your "planet" script
var dateOfBirth : float;
function Start() {
dateOfBirth = Time.timeSinceLevelLoad;
}
function OnCollisionEnter(other) {
otherPlanet = other.gameObject.GetComponent("planet");
if (otherPlanet && otherPlanet.dateOfBirth < dateOfBirth) {
Destroy(other.gameObject);
}
}