Quantcast
Channel: Questions in topic: "dynamically"
Viewing all articles
Browse latest Browse all 152

Can you use "GetComponent" dynamically?

$
0
0
I'm using: public GameObject target; private ValueField valueField; void Awake (){ valueField = target.GetComponent(); } void OnMouseDown () { valueField.addValue(value); } It works great. I can set the target GameObject by drag and dropping it into the unity property inspector. I was wanting to also set the "Class" or "Script" or what ever you call it in the property inspector too. so something like: public varTargetGameObject; public varClassName; private varTargetInstance; varTargetInstance = varTargetGameObject.GetComponent(varClassName); Can you do something like that? What's the correct syntax?

Viewing all articles
Browse latest Browse all 152

Trending Articles



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