I want to make a script for editing a scene to make it easier to place down prefabs instead of duplicating and moving prefabs hundreds of times.
Here’s my script:
using UnityEngine;
using System.Collections;
public class LevelEditingScript : MonoBehaviour {
void Update () {
if (Input.GetKey(KeyCode.Space) && Input.GetMouseButtonDown(0)) {
Debug.Log("mouseclick");
GameObject objectPrefab = Instantiate (UnityEditor.Selection.activeObject) as GameObject;
objectPrefab.transform.position = Camera.main.ScreenToWorldPoint (Input.mousePosition);
objectPrefab.transform.position = new Vector3 (objectPrefab.transform.position.x, 0.1f, objectPrefab.transform.position.z);
objectPrefab.transform.SetParent (GameObject.Find ("Obstacles").transform);
}
}
}
This script instantiates the selected gameobject in the inspector when the space bar and left mouse button is clicked. I would instantiate things like trees, rocks and flowers.
Is there any way to run this script in the editor and not play mode?