- Home /
Add a Transform/GameObject to the selection from an editor script
Hi,
I'm making a kind of level editor using a JavaScript unity editor script. I wan't to be able to add a transform/gameobject to the selection array. I've tried using Selection.transforms and .objects but I keep getting Cast Exceptions. What is the best way to do this? My project won't work without it.
Here's my code as is
var clicked = GetGameObjectAtPoint(lastMouseUp); //Convert to JS array var a = new Array(Selection.objects); a.Push(clicked); //Convert back to Builtin array Selection.objects = a.ToBuiltin(UnityEngine.Object);
Thanks! :) - James
Answer by DaveA · May 27, 2011 at 11:17 PM
Selection.transforms is defined as static var transforms : Transform[]
which is not dynamically resizable, so you'd either need to convert to/from Array or allocate a larger Transform[] and assign it back to Selection.transforms. That said, I don't know if that will work or not.
Thanks, sorry I forgot to post my code, please have a look at my edits.
Answer by MountDoomTeam · Sep 22, 2012 at 07:37 PM
a different option to using Select to manipulate objects is to just add selections to prefabs to put them in a kind of memory you can re-use, and if you want to select stuff with the mouse and mod their attributes, you can make a tag called :select: and whatever objects you select get that tag, adn then you do take all objects tagged select and do whatever you wanted to them. did you get this working to add selections in code?
Your answer

Follow this Question
Related Questions
Rotating an object in position 2 Answers
How do I create an array for multiple targets? 1 Answer
Instantiate as a child at position 2 Answers
How to get info of object within certain range?(Javascript) 1 Answer
Position of a GameObject 2 Answers