void FixedUpdate() { //Get every object GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); //the gravity between each couple of object is calculated foreach (GameObject ObjectA in Objects) { foreach (GameObject ObjectB in Objects) { //Objects must not self interact if (ObjectA == ObjectB) { continue; } ApplyGravity(ObjectA.GetComponent <Rigidbody> (), ObjectB.GetComponent <Rigidbody> ()); } } }
void FixedUpdate() { //Get every object //GameObject[] Objects = GameObject.FindGameObjectsWithTag("Player"); List <GameObject> Objects = new List <GameObject>(GameObject.FindGameObjectsWithTag("Asteroid")); Objects.Add(GameObject.FindGameObjectWithTag("Sun")); //the gravity between each couple of object is calculated foreach (GameObject ObjectA in Objects) { foreach (GameObject ObjectB in Objects) { //Objects must not self interact if (ObjectA == ObjectB) { continue; } ApplyGravity(ObjectA.GetComponent <Rigidbody2D>(), ObjectB.GetComponent <Rigidbody2D>()); } } }