|
@@ -0,0 +1,73 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using System.Linq;
|
|
|
+using JetBrains.Annotations;
|
|
|
+using Pools;
|
|
|
+using Roads;
|
|
|
+
|
|
|
+[Serializable]
|
|
|
+public struct RoutePoint
|
|
|
+{
|
|
|
+ //Point position
|
|
|
+ public string name;
|
|
|
+ public float x;
|
|
|
+ public float z;
|
|
|
+ public bool slalom;
|
|
|
+}
|
|
|
+
|
|
|
+public class CoinCreation : MonoBehaviour
|
|
|
+{
|
|
|
+ public int stepsize;
|
|
|
+ public CoinPool coinPool;
|
|
|
+ public List<RoutePoint> points = new List<RoutePoint>();
|
|
|
+ int pointIndex = 0;
|
|
|
+ private Vector3 coin_position;
|
|
|
+ private GameObject coin;
|
|
|
+
|
|
|
+ private void Start()
|
|
|
+ {
|
|
|
+ PlaceCoins();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void PlaceCoins()
|
|
|
+ {
|
|
|
+ //Abstand zwischen den Coins berechnen
|
|
|
+
|
|
|
+ RoutePoint start_point = points[pointIndex];
|
|
|
+ start_point.x = start_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
|
|
|
+
|
|
|
+ pointIndex++;
|
|
|
+
|
|
|
+ RoutePoint end_point = points[pointIndex];
|
|
|
+ end_point.x = end_point.x + 190f; //offset wegen relativen Kreuzungskoordinaten
|
|
|
+
|
|
|
+ float distance_x = System.Math.Abs(start_point.x - end_point.x);
|
|
|
+ float distance_z = System.Math.Abs(start_point.z - end_point.z);
|
|
|
+
|
|
|
+ float space_x = 0; //default
|
|
|
+ float space_z = 0; //default
|
|
|
+ if (distance_x > 0) // wenn entlang der x Richung verteilt wird
|
|
|
+ {
|
|
|
+ space_x = distance_x / stepsize;
|
|
|
+ }
|
|
|
+ if (distance_z > 0) // wenn entlang der z Richung verteilt wird
|
|
|
+ {
|
|
|
+ space_z = distance_z / stepsize;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i > stepsize; ++i)
|
|
|
+ {
|
|
|
+ //position berechnen
|
|
|
+ coin_position.x = start_point.x + i * space_x;
|
|
|
+ coin_position.y = 0.5f;
|
|
|
+ coin_position.z = start_point.z + i * space_z;
|
|
|
+
|
|
|
+ //Coin erstellen
|
|
|
+ coin = coinPool.GetItem();
|
|
|
+ coin.transform.position = coin_position;
|
|
|
+ coin.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|