- Home /
Another Java to C# Conversion Question!!
Another script I need help converting. Scenario: Have game object that has no renderer but children all do. I want to disable all of the children rendering.
So Search function is working managed to find this in Java
var renderers = GetComponentsInChildren(Renderer);
for (var r : Renderer in renderers) {
r.enabled = false;
}
Heres the stage I am at.
public GameObject gun;
SOMETHING? renderers = GetComponentsInChildren<Renderer>(); foreach(Renderer r in renderers) { r.enabled = false; }
I am still unsure on how parts of the script work exactly (thus why I havent put gun into the script in my conversion because I do not know where it goes) , I am trying to enabled/disable the render of the GameObject gun(all of its children)
Cheers, Aaron Lewis
Answer by tertle · Feb 16, 2011 at 04:51 AM
var renderers = GetComponentsInChildren<Renderer>();
for (var r in renderers) {
r.enabled = false;
}
TBH I'm not sure why so many people have issues converting from javascript to c# if they understand c#. I have never touched javascript yet a 2s look at unity manual shows the minor differences in functions.
Anyway what I posted should work fine assuming it's within a function, c# supports the var keyword (works differently though.)
If you care about having types there
Renderer[] renderers = GetComponentsInChildren<Renderer>();
for (Renderer r in renderers) {
r.enabled = false;
}
Your answer
Follow this Question
Related Questions
Enable/Disable GameObject Button script 1 Answer
Unable to enable script 0 Answers
Disabled Script still does OnMouseDown 1 Answer
I need to find a Script and Disable/enable it.. 1 Answer
Disable a script from another script 2 Answers