private void Update() { RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.right, distance); if (hitInfo.collider != null) { if (hitInfo.collider.CompareTag("Player") && player != null) { playerHealth.TakeDamage(damage); DestroyProjectile(); } } //transform.Translate(new Vector2(player.transform.position.x, player.transform.position.y) * speed * Time.deltaTime); transform.Translate(targetLocation * speed * Time.deltaTime, Space.World); }
void OnTriggerEnter2D(Collider2D other) { //If Bullet Hits Player we want to damage player and destory the bullet. if (other.tag == "Player") { print("Enemy Damaged the Player"); Destroy(gameObject); playerHealth.TakeDamage(damage); } //Make sure that if the bullet collides with any other collider it should also destroy. // However we remove destruction IF impact on Enemy or Carrot occurs. This is a safety-net for the FriendlyFire system. else if (other.tag != "Enemy" && other.tag != "Carrot" && other.tag != "NotCarrot") { Destroy(gameObject); } }