Question by
Tannerhaley21 · Oct 18, 2016 at 05:05 AM ·
transformforeachmethods
Accessing transform child in foreach loop
foreach (Transform t in this.transform) {
totalWeight = totalWeight + t.CalculateWeight();
return totalWeight; }
It won't let me access CalculateWeight() which is a method of the child classes. What am i doing wrong?
Comment
Answer by SmomoGame · Oct 19, 2016 at 09:11 AM
If you want to get the function in your custom script, you must "Get" your script first.
foreach (Transform t in this.transform) {
totalWeight = totalWeight + t.GetComponent<YourScript>().CalculateWeight();
return totalWeight;
}
Your answer
Follow this Question
Related Questions
Looking through all the children doesn't work 1 Answer
For and Foreach not getting all child transform 0 Answers
how to gameobject timed destroy with effect 0 Answers
Dashing cube forward problem 1 Answer