void OnTriggerEnter2D(Collider2D hitInfo) { // Debug.Log(hitInfo.name); if (hitInfo.tag == "Player") { MyPlayerHealth playerHealth = hitInfo.GetComponent <MyPlayerHealth>(); Transform playerTransform = hitInfo.GetComponent <Transform>(); if (playerHealth != null) { if (transform.position.x > playerTransform.position.x) { playerHealth.TakeDamage(damage, true); //Debug.Log("go left"); } else { playerHealth.TakeDamage(damage, false); //Debug.Log("go right"); } } GameObject boom = Instantiate(impactEffect, transform.position, transform.rotation); Destroy(gameObject); Destroy(boom, time); } }
void Attack() { timer = 0; if (myPlayerHealth.currentHealth > 0) { myPlayerHealth.TakeDamage(attackDamage); } }
IEnumerator Attack() { if (playerHealth != null && !isAttacking) { isAttacking = true; Debug.Log("call take"); if (transform.position.x > player.position.x) { playerHealth.TakeDamage(damage, true); //Debug.Log("go left"); } else { playerHealth.TakeDamage(damage, false); //Debug.Log("go right"); } yield return(new WaitForSeconds(attackingDelay)); isAttacking = false; } }