TheKingsRace/Assets/Scripts/CoolDown.cs
Melbyj1125 3ca497b913 Inventory is a dictionary
Inventory Networking
2021-11-19 13:44:36 -06:00

52 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoolDown : MonoBehaviour
{
public PlayerInventory Inv;
private List<SpecialItem> specialItems = new List<SpecialItem>();
public GameObject uiPrebab;
// Start is called before the first frame update
void Start(){
//retrieve all items that are special items here
foreach(var I in Inv.PlayerItemDict){
if(I.Value.GetType() == typeof(SpecialItem)){
SpecialItem temp = (SpecialItem)I.Value;
//if not
if(temp.cooldownM == 0 || I.Value.GetType() != typeof(SpecialItem)){
Debug.Log("Item not fully intialized");
//throw assert
Debug.Assert(temp.cooldownM != 0);
Debug.Assert(I.Value.GetType() == typeof(SpecialItem));
}
specialItems.Add(temp);
}
}
//set up ui elements for special items
for(int i = 0; i < specialItems.Count; i++){
//instantiate prefab
GameObject temp = Instantiate(uiPrebab);
temp.transform.SetParent(this.gameObject.transform);
SpecialItem currentSpecialItem = specialItems[i];
temp.name = currentSpecialItem.itemName;
//set position
temp.transform.localPosition = new Vector3(-290, 110 - (i * 50), temp.transform.position.z);
temp.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
//set cooldown on ui
temp.GetComponent<UICoolDown>().setCoolDownTime(currentSpecialItem.cooldownM);
}
}
public void startUICooldown(string name){
this.gameObject.transform.Find(name).GetComponent<UICoolDown>().startCoolDown();
}
// Update is called once per frame
void Update()
{
}
}