private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.tag == "Ground") { rb.constraints = RigidbodyConstraints2D.FreezeAll; } if (collision.transform.name == "Player") { PlayerController pC = collision.transform.GetComponent <PlayerController>(); pC.lives++; pC.updateHealthUI(); wepText.text = "Extra Life"; wepText.rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(transform.position); int z = Random.Range(-45, 45); wepText.rectTransform.localEulerAngles = new Vector3(0, 0, z); wepText.GetComponent <WeaponText>().lerp = true; bS.spawnTheBox(); Enemy enem = GameObject.Find("Enemy").GetComponent <Enemy>(); enem.goToPackage = false; Destroy(transform.gameObject); } else if (collision.transform.name == "Enemy") { Enemy eN = collision.transform.GetComponent <Enemy>(); eN.lives++; eN.updateHealthUI(); wepText.text = "Extra Life"; wepText.rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(transform.position); int z = Random.Range(-45, 45); wepText.rectTransform.localEulerAngles = new Vector3(0, 0, z); wepText.GetComponent <WeaponText>().lerp = true; bS.spawnTheBox(); Enemy enem = GameObject.Find("Enemy").GetComponent <Enemy>(); enem.goToPackage = false; Destroy(transform.gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.transform.tag == "Ground") { bC.isTrigger = false; rB.constraints = RigidbodyConstraints2D.FreezeAll; sR.sprite = boxWithoutPara; } else if (collision.transform.tag == "Player") { giveWeapons(0); wepText.rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(transform.position); int z = Random.Range(-45, 45); wepText.rectTransform.localEulerAngles = new Vector3(0, 0, z); wepText.GetComponent <WeaponText>().lerp = true; Enemy enem = GameObject.Find("Enemy").GetComponent <Enemy>(); enem.goToPackage = false; Destroy(gameObject); bS.spawnTheBox(); } else if (collision.transform.tag == "Enemy") { giveWeapons(1); wepText.rectTransform.anchoredPosition = Camera.main.WorldToScreenPoint(transform.position); int z = Random.Range(-45, 45); wepText.rectTransform.localEulerAngles = new Vector3(0, 0, z); wepText.GetComponent <WeaponText>().lerp = true; Enemy enem = GameObject.Find("Enemy").GetComponent <Enemy>(); enem.goToPackage = false; Destroy(gameObject); bS.spawnTheBox(); } }