CoinCreation.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Linq;
  5. using JetBrains.Annotations;
  6. using Pools;
  7. using Roads;
  8. [Serializable]
  9. public struct RoutePoint
  10. {
  11. //Point position
  12. public string name;
  13. public float x;
  14. public float z;
  15. public bool slalom;
  16. }
  17. public class CoinCreation : MonoBehaviour
  18. {
  19. public int stepsize;
  20. public CoinPool coinPool;
  21. public List<RoutePoint> points = new List<RoutePoint>();
  22. int pointIndex = 0;
  23. private Vector3 coin_position;
  24. private GameObject coin;
  25. private void Start()
  26. {
  27. PlaceCoins();
  28. }
  29. public void PlaceCoins()
  30. {
  31. //Abstand zwischen den Coins berechnen
  32. RoutePoint start_point = points[pointIndex];
  33. start_point.x = start_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
  34. pointIndex++;
  35. RoutePoint end_point = points[pointIndex];
  36. end_point.x = end_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
  37. float distance_x = System.Math.Abs(start_point.x - end_point.x);
  38. float distance_z = System.Math.Abs(start_point.z - end_point.z);
  39. float space_x = 0; //default
  40. float space_z = 0; //default
  41. if (distance_x > 0) // wenn entlang der x Richung verteilt wird
  42. {
  43. space_x = distance_x / stepsize;
  44. }
  45. if (distance_z > 0) // wenn entlang der z Richung verteilt wird
  46. {
  47. space_z = distance_z / stepsize;
  48. }
  49. for (int i = 0; i > stepsize; ++i)
  50. {
  51. //position berechnen
  52. coin_position.x = start_point.x + i * space_x;
  53. coin_position.y = 0.5f;
  54. coin_position.z = start_point.z + i * space_z;
  55. //Coin erstellen
  56. coin = coinPool.GetItem();
  57. coin.transform.position = coin_position;
  58. coin.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
  59. }
  60. }
  61. }