Add plate spawning counter
This commit is contained in:
parent
9da447f835
commit
7a3073ea8a
13 changed files with 891 additions and 92 deletions
43
Assets/Scripts/Counters/PlatesCounterVisual.cs
Normal file
43
Assets/Scripts/Counters/PlatesCounterVisual.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlatesCounterVisual : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private PlatesCounter platesCounter;
|
||||
[SerializeField] private Transform counterTopPoint;
|
||||
[SerializeField] private Transform plateVisualPrefab;
|
||||
|
||||
private List<GameObject> plateVisualGameObjectList;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
plateVisualGameObjectList = new List<GameObject>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
platesCounter.OnPlateSpawned += PlatesCounter_OnPlateSpawned;
|
||||
platesCounter.OnPlateRemoved += PlatesCounter_OnPlateRemoved;
|
||||
}
|
||||
|
||||
private void PlatesCounter_OnPlateRemoved(object sender, System.EventArgs e)
|
||||
{
|
||||
GameObject plateGameObject = plateVisualGameObjectList[plateVisualGameObjectList.Count - 1];
|
||||
|
||||
plateVisualGameObjectList.Remove(plateGameObject);
|
||||
|
||||
Destroy(plateGameObject);
|
||||
}
|
||||
|
||||
private void PlatesCounter_OnPlateSpawned(object sender, System.EventArgs e)
|
||||
{
|
||||
Transform plateVisualTransform = Instantiate(plateVisualPrefab, counterTopPoint);
|
||||
|
||||
float plateOffsetY = .1f;
|
||||
plateVisualTransform.localPosition = new Vector3(0, plateOffsetY * plateVisualGameObjectList.Count, 0);
|
||||
|
||||
plateVisualGameObjectList.Add(plateVisualTransform.gameObject);
|
||||
|
||||
}
|
||||
}
|
Reference in a new issue