public void SetState(_celestialObject data) { rigidBody = this.gameObject.GetComponent <Rigidbody>(); if (rigidBody == null) { rigidBody = this.gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody; } staticBody = data.staticBody; velocity = data.velocity; //rigidBody.position = data.position; transform.position = data.position; rigidBody.position = data.position; RotationSim rot = this.gameObject.GetComponent <RotationSim>(); if (rot != null) { this.gameObject.GetComponent <RotationSim>().SetState(true); this.gameObject.GetComponent <RotationSim>().SetRotation(data.rotation[0], data.rotation[1]); this.gameObject.GetComponent <RotationSim>().StartRotation(true); this.gameObject.GetComponent <RotationSim>().Deploy(); } else { this.gameObject.AddComponent(typeof(RotationSim)); this.gameObject.GetComponent <RotationSim>().SetState(true); this.gameObject.GetComponent <RotationSim>().SetRotation(data.rotation[0], data.rotation[1]); this.gameObject.GetComponent <RotationSim>().StartRotation(true); this.gameObject.GetComponent <RotationSim>().Deploy(); } mass = data.mass; rigidBody.mass = mass; name = data.name; if (name != null) { txt = Resources.Load("PlanetNameText/PlanetName") as GameObject; Vector3 newpos = this.gameObject.transform.position; newpos = newpos + new Vector3(0f, 0.2f, 0f); txt = Instantiate(txt, newpos, this.gameObject.transform.rotation); //txt.transform.SetParent(this.gameObject.transform, false); txt.AddComponent <PlanetNameMovement>(); textTranslation = data.textTranslation; txt.GetComponent <PlanetNameMovement>().SetPlanet(this.gameObject, data.textTranslation); txt.GetComponent <TextMesh>().text = name; } if (staticBody) { rigidBody.isKinematic = true; this.gameObject.transform.position = data.position; } else { rigidBody.isKinematic = false; } gameObject.GetComponent <AudioSource>().Play(); isShot = true; }
public void CollectData() { //increase starting i if adding to existing system? int rockyAdded = 0; int gasyAdded = 0; int count = 0; for (int i = 0; i < CelestialObject.Objects.Count; i++) { CelestialObject co = CelestialObject.Objects[i]; if (!co.staticBody) { physicsData[count] = new _celestialObject(co, count); IcoPlanet ip = co.GetComponentInChildren <IcoPlanet>(); if (ip != null) { planetList[rockyAdded] = new _planet(ip, count); rockyAdded += 1; } GasPlanetShaderMAterialPropertyBlock gp = co.GetComponentInChildren <GasPlanetShaderMAterialPropertyBlock>(); if (gp != null) { gasPlanetList[gasyAdded] = new _gasPlanet(gp, count); gasyAdded += 1; } count += 1; } } }