TC_SpawnTerrainHeight.cs 828 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TerrainComposer2
  4. {
  5. [ExecuteInEditMode]
  6. public class TC_SpawnTerrainHeight : MonoBehaviour
  7. {
  8. public float heightOffset = 0;
  9. Transform t;
  10. void Start()
  11. {
  12. t = transform;
  13. SetSpawnHeight();
  14. }
  15. #if UNITY_EDITOR
  16. void Update()
  17. {
  18. if (Application.isPlaying) return;
  19. SetSpawnHeight();
  20. }
  21. #endif
  22. void SetSpawnHeight()
  23. {
  24. Ray ray = new Ray(t.position + new Vector3(0, 10000, 0), Vector3.down);
  25. RaycastHit hit;
  26. if (Physics.Raycast(ray, out hit))
  27. {
  28. t.position = new Vector3(t.position.x, hit.point.y + heightOffset, t.position.z);
  29. }
  30. }
  31. }
  32. }