private void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Enemy") { if (Vector3.Distance(player.transform.position, this.transform.position) < 1.0f) { EnemyAttacked ea = coll.gameObject.GetComponent <EnemyAttacked>(); ea.KnockDownEnemy(); } } }
public void attack() { pa.Attack(); if (gun == true && curWepScr.ammo > 0) { pa.Attack(); Bullet bul = bullet.GetComponent <Bullet>(); Bullet shotGunBul = bullet.GetComponent <Bullet>(); Vector3 direction; direction.x = Vector2.right.x; direction.y = Vector2.right.y; direction.z = 0; bul.SetValues(direction, "Player"); if (oneHanded) { Instantiate(bullet, oneHandSpawn.transform.position, this.transform.rotation); curWeapon.GetComponent <WeaponPickUp>().ammo--; } else { Instantiate(shotgunBullet, twoHandSpawn.transform.position, this.transform.rotation); curWeapon.GetComponent <WeaponPickUp>().ammo--; } timer = timerReset; } else { int layerMask = 1 << 9; layerMask = ~layerMask; pa.Attack(); RaycastHit2D rayCast = Physics2D.Raycast(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), layerMask); Debug.DrawRay(new Vector2(this.transform.position.x, this.transform.position.y), new Vector2(transform.right.x, transform.right.y), Color.green); if (curWeapon == null && rayCast.collider.gameObject.tag == "Enemy") { Debug.Log("hit"); EnemyAttacked enemyAttacked = rayCast.collider.gameObject.GetComponent <EnemyAttacked>(); enemyAttacked.KnockDownEnemy(); } timer = timerReset; } }
void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.tag == "Enemy") { attacked = collider.gameObject.GetComponent <EnemyAttacked>(); attacked.KnockDownEnemy(); rid.isKinematic = false; Destroy(this); } else if (collider.gameObject.tag == "Player") { } else { rid.isKinematic = true; Destroy(this); } }