private void OnTriggerStay2D(Collider2D collision) { if (collision.GetComponent <ItemScript>() != null && Vector3.Distance(collision.transform.position, transform.position) <= .1f && curEnergy >= 4) //Pick up an item { if (!collision.GetComponent <ItemScript>().Buyable) { if (inventory.AddItem(collision.GetComponent <ItemScript>())) { aMH.NewLogMessage(string.Format("{0} picked up {1}!", statHandler.entityName, collision.GetComponent <ItemScript>().Item.itemName)); Destroy(collision.gameObject); } } else { objOntopOf = collision.gameObject; } } if (transform.tag == "Player" && collision.tag == "Stairs" && Vector3.Distance(collision.transform.position, transform.position) <= .1f && curEnergy >= 4) { Debug.Log("Next Floor!"); GameObject.Find("Game Manager").GetComponent <FloorManager>().NextFloor(); } if (collision.GetComponent <WeaponHandler>() != null && Vector3.Distance(collision.transform.position, transform.position) <= .1f) { WeaponHandler weapon = collision.GetComponent <WeaponHandler>(); if (!weapon.IsThrown) { return; } if (weapon.parentObject == this.gameObject) { return; } EntityStatHandler statHandler = GetComponent <EntityStatHandler>(); EntityStatHandler eStatHandler = collision.GetComponent <WeaponHandler>().parentObject.GetComponent <EntityStatHandler>(); lastHitBy = collision.GetComponent <WeaponHandler>().parentObject; switch (weapon.ScaledStat) { case statType.strength: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Str, eStatHandler.Level); break; case statType.dexterity: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Dex, eStatHandler.Level); break; case statType.inteligence: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Intl, eStatHandler.Level); break; case statType.defense: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Def, eStatHandler.Level); break; } weapon.AttackFinished(); GetComponent <EntityAnimation>().isHurt = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.GetComponent <WeaponHandler>() != null) { WeaponHandler weapon = collision.GetComponent <WeaponHandler>(); if (weapon.IsThrown) { return; } if (weapon.parentObject == this.gameObject) { return; } EntityStatHandler statHandler = GetComponent <EntityStatHandler>(); EntityStatHandler eStatHandler = collision.GetComponent <WeaponHandler>().parentObject.GetComponent <EntityStatHandler>(); lastHitBy = collision.GetComponent <WeaponHandler>().parentObject; switch (weapon.ScaledStat) { case statType.strength: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Str, eStatHandler.Level); break; case statType.dexterity: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Dex, eStatHandler.Level); break; case statType.inteligence: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Intl, eStatHandler.Level); break; case statType.defense: statHandler.TakeDamage(weapon.WeaponDamage, eStatHandler.Def, eStatHandler.Level); break; } GetComponent <EntityAnimation>().isHurt = true; } }