// Use this for initialization void Start() { GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); //the gravity between each couple of object is calculated foreach (GameObject ObjectA in Objects) { ObjectA.GetComponent <Rigidbody>().AddForce(new Vector3(10, 10, 10)); } }
void Start() { //Creates array of all objects in scene with the tag "Planet" GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); foreach (GameObject ObjectA in Objects) { //Creates Vector3 from the variabe saved in GravitySpecs Vector3 movement = ObjectA.GetComponent <GravitySpecs>().movement; //Adds the movement vector to the ridgidbody attached to the planet ObjectA.GetComponent <Rigidbody>().AddForce(movement); } }
void Start() { //CamSwitch foreach (GameObject camera in cameraList) { camera.SetActive(false); } //Gravity GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); foreach (GameObject ObjectA in Objects) { Vector3 movement = ObjectA.GetComponent <GravitySpecs>().movement; ObjectA.GetComponent <Rigidbody>().AddForce(movement); } }
// Use this for initialization void Start() { GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); GameObject Spaceship = GameObject.FindGameObjectWithTag("SpaceShip"); //the gravity between each couple of object is calculated foreach (GameObject ObjectA in Objects) { ObjectA.GetComponent <Rigidbody>().AddForce(new Vector3(10, 10, 0)); } //gravity for the spaceship //Modified by Olga on 02/21/2017 //I am restricting this to the x axis so the spaceship doesn't spin so much Spaceship.GetComponent <Rigidbody> ().AddForce(new Vector3(50, 0, 0)); }
void FixedUpdate() { //If variable sun is not set in scene the on=bject will be found automatically if (Sun == null) { Sun = GameObject.Find("Sun"); } //Make sure the array contains the planets GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); //Calls ApplyGravity function for each planet and sun foreach (GameObject ObjectA in Objects) { ApplyGravity(ObjectA.GetComponent <Rigidbody>(), Sun.GetComponent <Rigidbody>()); } }
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() { //Gravity if (Sun == null) { Sun = GameObject.Find("Sun"); } GameObject[] Objects = GameObject.FindGameObjectsWithTag("Planet"); foreach (GameObject ObjectA in Objects) { ApplyGravity(ObjectA.GetComponent <Rigidbody>(), Sun.GetComponent <Rigidbody>()); } //Scale if (Input.GetKey(KeyCode.UpArrow) && !Scaled) { for (int i = 0; i < 9; i++) { Planets[i].transform.position = Planets[i].transform.position * Distances[i]; Planets[i].transform.localScale += Scale[i]; Rigidbody rb = Planets[i].GetComponent <Rigidbody>(); rb.mass += ScaledMasses[i]; Moon.transform.localScale = new Vector3(0.101f, 0.101f, 0.101f); } Scaled = true; } if (Input.GetKey(KeyCode.DownArrow) && Scaled) { for (int i = 0; i < 9; i++) { Planets[i].transform.position = Planets[i].transform.position / Distances[i]; Planets[i].transform.localScale -= Scale[i]; Rigidbody rb = Planets[i].GetComponent <Rigidbody>(); rb.mass -= ScaledMasses[i]; Moon.transform.localScale = new Vector3(0.17f, 0.17f, 0.17f); } Scaled = false; } }
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>()); } } }