• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by loganaz · Oct 03, 2016 at 06:00 AM · cameraeditorinspectorspawningapi

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>();
 }
     }
 }

,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Skybox - Render Settings vs on a Camera 0 Answers

Custom Inspector (Editor) - override just one field control 0 Answers

Best way to manage multiple camera angles? 3 Answers

How to reduce cam speed in the editor? 5 Answers

Problem with MaskField ints 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges