WallCreate.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class WallCreate : MonoBehaviour
  6. {
  7. public float Height = 1f;
  8. public int Rounding = 1;
  9. public bool move = false;
  10. public bool BoxColliderEnabled = true;
  11. //GameObject cursor_end;
  12. private Vector3 screenPoint;
  13. private Vector3 offset;
  14. private Vector3 curScreenPoint;
  15. private Vector3 curPosition;
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. // gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  20. //cursor_end = transform.GetChild(6).gameObject;
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. // if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  26. }
  27. void OnMouseDown()
  28. {
  29. //Debug.Log(StagesEditorController.indexCursor);
  30. screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
  31. offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
  32. }
  33. // Перемещение
  34. void OnMouseDrag()
  35. {
  36. curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
  37. curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
  38. var x = (float)Math.Round(curPosition.x, Rounding);
  39. var z = (float)Math.Round(curPosition.z, Rounding);
  40. //transform.position = new Vector3(x, Height, z);
  41. //gameObject.GetComponent<BoxCollider>().size = new Vector3(x, Height, z);
  42. var pos = new Vector3(x, transform.localScale.y / 2f, z);
  43. transform.position = pos;
  44. //LocationController.Cube(gameObject, );
  45. AddWall(pos);
  46. }
  47. void AddWall(Vector3 pos)
  48. {
  49. var wall = Instantiate(Resources.Load("GameObjects/Pole", typeof(GameObject))) as GameObject;
  50. wall.transform.position = pos;
  51. }
  52. }