ProceduralController.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. namespace Photon.Pun.Demo.Procedural
  3. {
  4. /// <summary>
  5. /// Simple Input Handler to control the camera.
  6. /// </summary>
  7. public class ProceduralController : MonoBehaviour
  8. {
  9. private Camera cam;
  10. #region UNITY
  11. public void Awake()
  12. {
  13. cam = Camera.main;
  14. }
  15. /// <summary>
  16. /// Use horizontal and vertical axes (by default WASD or the arrow keys) for moving for-, back- or sidewards.
  17. /// Use E or Q for 'zooming' in or out.
  18. /// Use the left mouse button to decrease a Block's height
  19. /// or the right mouse button to increase a Block's height.
  20. /// </summary>
  21. public void Update()
  22. {
  23. float h = Input.GetAxisRaw("Horizontal");
  24. float v = Input.GetAxisRaw("Vertical");
  25. if (h >= 0.1f)
  26. {
  27. cam.transform.position += Vector3.right * 10.0f * Time.deltaTime;
  28. }
  29. else if (h <= -0.1f)
  30. {
  31. cam.transform.position += Vector3.left * 10.0f * Time.deltaTime;
  32. }
  33. if (v >= 0.1f)
  34. {
  35. cam.transform.position += Vector3.forward * 10.0f * Time.deltaTime;
  36. }
  37. else if (v <= -0.1f)
  38. {
  39. cam.transform.position += Vector3.back * 10.0f * Time.deltaTime;
  40. }
  41. if (Input.GetKey(KeyCode.Q))
  42. {
  43. cam.transform.position += Vector3.up * 10.0f * Time.deltaTime;
  44. }
  45. else if (Input.GetKey(KeyCode.E))
  46. {
  47. cam.transform.position += Vector3.down * 10.0f * Time.deltaTime;
  48. }
  49. if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
  50. {
  51. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  52. RaycastHit hit;
  53. if (Physics.Raycast(ray, out hit, 100.0f))
  54. {
  55. Block b = hit.transform.GetComponent<Block>();
  56. if (b != null)
  57. {
  58. if (Input.GetMouseButtonDown(0))
  59. {
  60. WorldGenerator.Instance.DecreaseBlockHeight(b.ClusterId, b.BlockId);
  61. }
  62. else if (Input.GetMouseButtonDown(1))
  63. {
  64. WorldGenerator.Instance.IncreaseBlockHeight(b.ClusterId, b.BlockId);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. #endregion
  71. }
  72. }