private void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "Cadavre") { dataBank = null; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Cadavre") { dataBank = collision.gameObject.GetComponent <CorpseBehavior>(); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.L)) { hp--; } if (data.Count > dataCap) { data.RemoveAt(data.Count - 1); Debug.Log("you went over your data cap!"); } if (hp > hpCap) { hp = hpCap; Debug.Log("can't have more life"); } if (dataBank != null) { if (data.Count < dataCap) { if (dataBank.Data > 0) { if (!nfc) { nfc = true; A = StartCoroutine(DATAsteal(dataBank, 2f)); } } else { dataBank = null; } } } if ((nfc) && (dataBank == null)) { StopCoroutine(A); nfc = false; dataUI.transform.GetChild(3).GetChild(0).gameObject.SetActive(false); } dataUI.transform.GetChild(1).GetChild(1).GetComponent <Image>().fillAmount = hp / hpCap; dataUI.transform.GetChild(0).GetChild(1).GetComponent <Image>().fillAmount = (float)data.Count / dataCap; }
IEnumerator DATAsteal(CorpseBehavior corpse, float time) { dataUI.transform.GetChild(3).GetChild(0).gameObject.SetActive(true); float animationTime = 0; while (animationTime < time) { animationTime += 0.01f; dataUI.transform.GetChild(3).GetChild(0).GetComponent <Image>().fillAmount = animationTime / time; yield return(new WaitForSeconds(0.01f)); } corpse.Data--; data.Add(0); nfc = false; dataUI.transform.GetChild(3).GetChild(0).gameObject.SetActive(false); }