123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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();
- }
- int points_size = points.Count;
- public void PlaceCoins()
- {
- if ((pointIndex + 1) < points_size) // Check: sind noch mindestens 2 Punkte in der Liste?
- {
- //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);
- }
- }
- else
- {
- Debug.Log("The End of the Route is near, so no new coins needed!");
- }
- }
- }
|