This repository has been archived on 2025-03-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
mojo-kitchen-chaos/Assets/Scripts/Counters/PlatesCounterVisual.cs

43 lines
1.3 KiB
C#

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);
}
}