Quantcast
Channel: Latest Questions by alexkaskasoli
Viewing all articles
Browse latest Browse all 56

Getting all scripts attached to a gameObject (Problem)

$
0
0
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.

Viewing all articles
Browse latest Browse all 56

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>