CoinCreation.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. int points_size = points.Count;
  30. public void PlaceCoins()
  31. {
  32. if ((pointIndex + 1) < points_size) // Check: sind noch mindestens 2 Punkte in der Liste?
  33. {
  34. //Abstand zwischen den Coins berechnen
  35. RoutePoint start_point = points[pointIndex];
  36. start_point.x = start_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
  37. pointIndex++;
  38. RoutePoint end_point = points[pointIndex];
  39. end_point.x = end_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
  40. float distance_x = System.Math.Abs(start_point.x - end_point.x);
  41. float distance_z = System.Math.Abs(start_point.z - end_point.z);
  42. float space_x = 0; //default
  43. float space_z = 0; //default
  44. if (distance_x > 0) // wenn entlang der x Richung verteilt wird
  45. {
  46. space_x = distance_x / stepsize;
  47. }
  48. if (distance_z > 0) // wenn entlang der z Richung verteilt wird
  49. {
  50. space_z = distance_z / stepsize;
  51. }
  52. for (int i = 0; i > stepsize; ++i)
  53. {
  54. //position berechnen
  55. coin_position.x = start_point.x + i * space_x;
  56. coin_position.y = 0.5f;
  57. coin_position.z = start_point.z + i * space_z;
  58. //Coin erstellen
  59. coin = coinPool.GetItem();
  60. coin.transform.position = coin_position;
  61. coin.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
  62. }
  63. }
  64. else
  65. {
  66. Debug.Log("The End of the Route is near, so no new coins needed!");
  67. }
  68. }
  69. }