Unable to effect movement on active game object
Dear community,
I am trying to effect movement on my active asteroid game object, which has been saved as a prefab. Previously when I had the script attached directly to my asteroid prefab, all was simple and it moved as intended:
public float speed;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody> ();
rb.velocity = transform.right * speed;
}
I am now instead trying to create a library containing all my asteroids and effecting their different movements through a single script. I created an empty game object, in which I created different arrays to hold my different asteroid prefabs. My asteroid prefabs have had their original movement script above removed. My script is as follows:
public GameObject[] asteroidsLeftward;
public GameObject[] asteroidsDownward;
public GameObject[] asteroidsUpward;
public GameObject[] asteroidsRightward;
void Start ()
{
for (int L = 0; L < asteroidsLeftward.Length; L++) {
asteroidsLeftward [L].GetComponent<Rigidbody> ().velocity = transform.right * 2;
Debug.Log (asteroidsLeftward [L].GetComponent<Rigidbody> ().velocity);
}
}
I have only written the script for my first array of asteroids, but my asteroids do not move at all. They are active in the scene, and the console displays the velocity Vector3 values correctly. Is there a mistake somewhere, or is my thought process fundamentally wrong?
Thank you!