12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using UnityEngine;
- using System.Collections.Generic;
- public class RingsManager : MonoBehaviour
- {
- public Transform ringsAnchor;
- public PoolObject ringPrefab;
- const float SPACING_BETWEEN_RINGS = 475;
- List<PoolObject> _placedRings = new List<PoolObject>();
- void OnDisable()
- {
- foreach (PoolObject ring in _placedRings)
- {
- ring.Despawn();
- }
- _placedRings.Clear();
- }
- public void CreateUpTo(float endX)
- {
- //if the player is switching between global and facebook, we don't need to recreate the rings
- if (_placedRings.Count != 0)
- {
- return;
- }
- Pool pool = Pool.Get(ringPrefab);
- int numOfRings = (int)(endX / SPACING_BETWEEN_RINGS);
- for (int i = 0; i < numOfRings; i++)
- {
- PoolObject ring = pool.Spawn();
- _placedRings.Add(ring);
- /*if(ring.transform!=null){
- return;
- }*/
- Transform ringTransform = ring.transform;
- Vector3 originalScale = ringTransform.localScale;
- ringTransform.parent = ringsAnchor;
- ringTransform.localScale = originalScale;
- //The anchor is set to the right of the screen, and we go to the left
- ringTransform.localPosition = new Vector3(-i * SPACING_BETWEEN_RINGS, 0);
- float percentage = i / (float)numOfRings;
- ring.GetComponent<Ring>().SetAlphaFromPercentage(percentage);
- }
- }
- }
|