- Home /
Question by
icelated · Sep 17, 2012 at 12:55 AM ·
c#javascriptrendererloops
loop through a renderer
I have a piece of java script code i am converting over to C# - Although, its wrong and i was hoping for some help since im getting an error.
Here is the java script
var gcic = GetComponentsInChildren(Renderer);
for(var go : Renderer in gcic){
go.renderer.enabled = false;
here is what i came up with so far:
Renderer gcic = GetComponentInChildren<Renderer>();
foreach(Renderer go in gcic){
go.renderer.enabled = false;
I do get an error that i cant use foreach on Renderer.
error CS1579: foreach statement cannot operate on variables of type `UnityEngine.Renderer' because it does not contain a definition for `GetEnumerator' or is not accessible
Comment
Best Answer
Answer by by0log1c · Sep 17, 2012 at 12:58 AM
Notice anything different in the method's name?
var gcic = GetComponentsInChildren(Renderer);
Renderer gcic = GetComponentInChildren<Renderer>();
You want to use GetComponentsInChildren to retrieve an array and not just the first one found:
Renderer[] gcic = GetComponentsInChildren<Renderer>();
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Multiple Cars not working 1 Answer
Javascript conversion question 2 Answers
Terrain Toolkit API 1 Answer