- Home /
Question by
Raj1v · May 05, 2012 at 02:30 PM ·
gameobjectscomponentsaddingall
How to add a component to all selected objects?
I didn't found a build in function anywhere so I decided to write my own.
This is my script
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
class AddCollideres
{
[MenuItem("Component/Plugins/Add colliders selected gameobjects")]
static void Execute()
{
foreach (GameObject obj in Selection.activeGameObject) {
Debug.Log(obj);
}
}
[MenuItem ("Component/Plugins/Add colliders to children", true)]
static bool ValidateSelection () {
return Selection.activeGameObject != null;
}
}
It isn't finished yet because i'm stuck. How do read multiple selected gameobjects?
[Edit by Berenger, code formatting]
Comment
Best Answer
Answer by Berenger · May 05, 2012 at 02:39 PM
Try this :
static void Execute()
{
foreach (GameObject obj in Selection.gameObjects) {
obj.AddComponent( typeof(...) );
}
}
Your answer
Follow this Question
Related Questions
Need a persistent unique id for gameobjects 11 Answers
Connecting two blendshapes 1 Answer
How to disable all objects but... 1 Answer
After days of looking for solutions, what's wrong with my array script? 2 Answers
Attach the ObjectManipulator MRTK component in runtime to instantiated GameObject? 0 Answers