- Home /
Having trouble accessing a unique instance of a dynamically generated script...
Hi. I'm having an issue assigning a value to a script in a dynamic object generated from a resource at runtime. In the below code, the value of direction in my apply forces script is always the value of the last element in the MotorDirection array. It's as if when I execute
QuadMotors.Props [i].transform.GetComponent ().direction = (int)MotorDirection [i];
It is assigning the value to all of the instances of this script. I only want it to assign to the one that belongs to the current instance of QuadMotors.Props, so that each instance has a different value.
public class FrameProperties : MonoBehaviour {
public Vector3[] attachmentPoints;
public MotorProperties.Direction[] MotorDirection;
private MotorController QuadMotors;
// Use this for initialization
void Start () {
QuadMotors = GetComponentInChildren<MotorController> ();
for (int i = 0; i < MotorDirection.Length; i++) {
QuadMotors.Props [i].transform.GetComponent<ApplyForces> ().direction = (int)MotorDirection [i];
Debug.Log ("frame direction " + (int)MotorDirection [i]);
}
}
Thank you.
Comment
I resolved this by assigning the value in the script that instantiated the objects. I think there are things I still don't understand about the order of execution at startup.