I am trying to Instatiate Objects with the code attached but only the first Object has the Method awake called and doesent get any values out of orbitValues. The other Objects get instantiated but they also dont get any values. Can you help please?
if (listChecked == true & objectsCreated == false)
{
objectsCreated = true;
for (int i = 0; i < 5 + 1; i++)
{
Ellipse orbitValues = new Ellipse(float.Parse(orbitList[i].attributes.inc), float.Parse(orbitList[i].attributes.sma), float.Parse(orbitList[i].attributes.ecc), float.Parse(orbitList[i].attributes.aPer));
Debug.Log("i: " + i + " aPer: " + orbitValues.aPer);
var tempOrbiter = Instantiate(orbit, Vector3.zero, transform.rotation);
tempOrbiter.GetComponent<OrbitMotion>().orbitPath = orbitValues;
tempOrbiter.GetComponent<OrbitMotion>().id = i;
tempOrbiter.transform.rotation = Quaternion.Euler(0, 0, orbitValues.inc);
tempOrbiter.transform.parent = GameObject.FindGameObjectWithTag("OrbiterGroup").transform;
}
}
The class Ellipse:
public class Ellipse
{
public float inc;
public float sma;
public float ecc;
public float aPer;
public float c;
public float e;
public float xAxis;
public float zAxis;
float x;
float z;
public Ellipse(float inc, float sma, float ecc, float aPer)
{
this.inc = inc;
this.sma = sma;
this.ecc = ecc;
this.aPer = aPer;
} ...
and the script that should be with every instantiated object:
public class OrbitMotion : MonoBehaviour
{
public Transform orbitingObject;
public Ellipse orbitPath;
public int id;
[Range(0f,1f)]
public float orbitProgress = 0f;
public float orbitPeriod = 60f;
public bool orbitActive = false;
public float xOffset = 0;
public float zOffset = 0;
void Awake()
{
Debug.Log("id: " + id);
Debug.Log(orbitPath.aPer);
if (orbitingObject == null)
{
orbitActive = false;
return;
}
orbitingObject = transform.GetChild(0).transform;
transform.parent = GameObject.Find("OrbiterGroup").transform;
transform.localRotation = Quaternion.Euler(0, 0, orbitPath.inc);
transform.localRotation = Quaternion.Euler(0, orbitPath.aPer, 0);
xOffset = (Mathf.Sin(orbitPath.aPer) * (orbitPath.sma - orbitPath.e));
zOffset = (Mathf.Cos(orbitPath.aPer) * (orbitPath.sma - orbitPath.e));
Debug.Log(orbitPath.e);
Debug.Log(xOffset);
transform.position = new Vector3(xOffset, 0, zOffset) / 1000;
SetOrbitingObjectPosition();
StartCoroutine(AnimateOrbit());
gameObject.GetComponent<EllipseRenderer>().ellipse = orbitPath;
}...
Instantiateand notnew.