Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Getting Variables From An Arbitrary Component?

$
0
0
I am familiar with the basic way of getting components by ASpecificComponent aSpecificComponent = (ASpecificComponent)transform.GetComponent("ASpecificComponent"); aSpecificComponent.anInt = 0; However, now I have an array of components and I want to do something like: compnentArray[1].anInt = 0; or Component aComponent = compnentArray[1]; aComponent.anInt = 0; Trying to do that yields this error: Assets/Scripts/CharController.cs(111,38): error CS1061: Type `UnityEngine.Component' does not contain a definition for `anInt' and no extension method `anInt' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?) I suspect that it is not possible to do what I want to do but that there is something else that you do in a situation like this. By the way, all of the scripts in the array of components have a variable named anInt.

Viewing all articles
Browse latest Browse all 171066

Trending Articles



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