// Update is called once per frame void Update() { if (life <= 0) { GameObject lt_gameObject = GameObject.FindGameObjectWithTag("Loot"); LootTables lt = lt_gameObject.GetComponent <LootTables>(); GameObject go; go = lt.looting(nombre); if (go != null) { if (go.GetComponent <Item>() != null) { go.GetComponent <Item>().tienda = false; } Instantiate(go, transform.position, Quaternion.identity); } int n = Random.Range(0, 99); if (n < 25) { go = lt.looting(nombre); if (go.GetComponent <Item>() != null) { go.GetComponent <Item>().tienda = false; } if (go != null) { Instantiate(go, transform.position, Quaternion.identity); } } Destroy(gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Hero") { GameObject lt_gameObject = GameObject.FindGameObjectWithTag("Loot"); LootTables lt = lt_gameObject.GetComponent <LootTables>(); go = lt.looting("Chest"); go.GetComponent <Item>().tienda = false; player = GameObject.FindGameObjectWithTag("Hero"); PlayerItems pi = player.GetComponent <PlayerItems>(); if (pi.llaves >= 1) { pi.llaves--; pi.UILlaves.text = "x " + pi.llaves.ToString("00"); Instantiate(go, transform.position, Quaternion.identity); Destroy(this.gameObject); } } }
// Update is called once per frame void Update() { animator.SetFloat("Speed", 0); if (!sFase && life <= (maxLife / 2)) { animator.SetBool("Fase2", true); speed *= 1.5f; sFase = true; } if (life <= 0) { animator.SetBool("HasLife", false); this.GetComponent <BoxCollider2D>().enabled = false; dieTime += Time.deltaTime; if (!looted) { int prob = 100; bool loot = true; GameObject lt_gameObject = GameObject.FindGameObjectWithTag("Loot"); LootTables lt = lt_gameObject.GetComponent <LootTables>(); GameObject go; while (loot) { int n = Random.Range(0, 99); if (n < prob) { go = lt.looting("Minotaur"); go.GetComponent <Item>().tienda = false; if (go != null) { Instantiate(go, transform.position, Quaternion.identity); } prob = (int)(prob / 2); } else { loot = false; looted = true; } } } if (dieTime >= 5) { SceneManager.LoadScene("Main Menu"); Destroy(this.gameObject); } } else { if (!animator.GetBool("Intro") && !animator.GetBool("Fase2")) { target = player.transform.position; float distx, disty; distx = target.x - transform.position.x; disty = target.y - transform.position.y; if ((Mathf.Abs(distx) <= radio && Mathf.Abs(disty) <= radio) && animator.GetInteger("Attack") == 0) { animator.SetInteger("Attack", 1); animator.SetFloat("Speed", 0); } else { if (animator.GetInteger("Attack") == 0) { /* if (distx >= 0) animator.SetBool("Left", false); * else animator.SetBool("Left", true);*/ transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime); animator.SetFloat("Speed", speed); } } } } }