using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class WallCreate : MonoBehaviour { public float Height = 1f; public int Rounding = 1; public bool move = false; public bool BoxColliderEnabled = true; //GameObject cursor_end; private Vector3 screenPoint; private Vector3 offset; private Vector3 curScreenPoint; private Vector3 curPosition; // Start is called before the first frame update void Start() { // gameObject.GetComponent().enabled = BoxColliderEnabled; //cursor_end = transform.GetChild(6).gameObject; } // Update is called once per frame void Update() { // if (gameObject.GetComponent().enabled != BoxColliderEnabled) gameObject.GetComponent().enabled = BoxColliderEnabled; } void OnMouseDown() { //Debug.Log(StagesEditorController.indexCursor); screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position); offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); } // Перемещение void OnMouseDrag() { curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z); curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset; var x = (float)Math.Round(curPosition.x, Rounding); var z = (float)Math.Round(curPosition.z, Rounding); //transform.position = new Vector3(x, Height, z); //gameObject.GetComponent().size = new Vector3(x, Height, z); var pos = new Vector3(x, transform.localScale.y / 2f, z); transform.position = pos; //LocationController.Cube(gameObject, ); AddWall(pos); } void AddWall(Vector3 pos) { var wall = Instantiate(Resources.Load("GameObjects/Pole", typeof(GameObject))) as GameObject; wall.transform.position = pos; } }