- Home /
New gameobject to spawn in front of editor camera?,
Right now when I click on menu "Composer Suite/Speaker" it will spawn the scripts components at the default location making it hard to find and time consuming to set up where I need it in the scene.
I just want it to spawn in front of the editor camera so I can set the scene up quicker! I'm very new to all of this, I would love for some help!
Thank you :)
using UnityEditor;
using UnityEngine;
public class SpeakerBoxS
{
[MenuItem("Composer Suite/Speaker")]
static void Create()
{
for (int x = 0; x != 1; x++)
{
GameObject go = new GameObject("Speaker Box");
go.transform.position = new Vector3(x, 0, 0);
go.AddComponent<AudioSource>();
go.AddComponent<BoxCollider>();
go.AddComponent<Gizspeaker>();
}
}
}
,
Answer by EvilTak · Oct 03, 2016 at 08:39 AM
The editor camera is usually Camera.current
when called from the editor. You can use its transform
property to get a Vector3
right in front of it. Something like
Camera.current.transform.TransformPoint(Vector3.forward * DistanceFromCamera);
It is better to use
SceneView.lastActiveSceneView.camera
instead
Your answer
Follow this Question
Related Questions
Skybox - Render Settings vs on a Camera 0 Answers
Notification of Game/Camera resize, in Editor. 0 Answers
Inspector turns black on refresh 4 Answers
Editor's Camera Clipping Plane 12 Answers
What should be handled in the custom inspector version of a script? 1 Answer