123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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<BoxCollider>().enabled = BoxColliderEnabled;
- //cursor_end = transform.GetChild(6).gameObject;
- }
- // Update is called once per frame
- void Update()
- {
- // if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().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<BoxCollider>().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;
- }
- }
|