GameObject go = GameObject.Instantiate(bullet, transform.position, Quaternion.identity) as GameObject;
Component[] c = go.GetComponents(MonoBehaviour);
foreach (MonoBehaviour script in c) {
script.direction = transform.position - target.transform.position;
}
I'm trying to access all the scripts attached on the game object I just instantiated. I get an error on the second line: "Expression denotes a type where a variable, value or method group was expected.
From what I can understand that should be the proper way to use GetComponents() but the C# documentation on rarely used methods is quite sparse.
↧