- Home /
Select all game objects with a component
I'm am new to unity and i'm trying to select all the game objects in the scene except the camera, to change the game object color.
How could I exclude the camera from being selected ?
Here is the code I use (JS) :
#pragma strict
var h : float = 0;
var s : float = 0.8;
var v : float = 1;
function Start () { changeColor(); }
function changeColor () {
var objects : GameObject[] = FindObjectsOfType(GameObject);
while (true) {
for (var obj : GameObject in objects) {
if (h < 1)
h = h+0.005;
else
h = 0;
obj.renderer.material.color = EditorGUIUtility.HSVToRGB(h,s,v);
yield WaitForSeconds(0.1);
}
}
}
Answer by robertbu · Apr 21, 2014 at 03:59 PM
Rather than exclude the camera from the list, exclude the camera from the processing. Insert as the first line in your for() loop:
if (obj == Camera.main.gameObject) continue;
Thanks ! Your code really helped me, even if I use another code now if (obj.GetComponent(Renderer) != null)
Your answer
Follow this Question
Related Questions
Camera Move 1 Answer
How do I disable Script on FP Controller? (Solved) 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Set Objects Child to Active/Inactive(Solved) 5 Answers
destroy hinge joint component from another object in javascript 2 Answers