void Shoot() { timer = 0f; gunAudio.Play(); gunLight.enabled = true; gunParticles.Stop(); gunParticles.Play(); gunLine.enabled = true; gunLine.SetPosition(0, transform.position); shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) { MyEnemyHealth myEnemyHealth = shootHit.collider.GetComponent <MyEnemyHealth>(); if (myEnemyHealth != null) { myEnemyHealth.TakeDamage(damagePerShot, shootHit.point); } gunLine.SetPosition(1, shootHit.point); } else { gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
void OnTriggerEnter2D(Collider2D hitInfo) { if (hitInfo.name != "Player" && hitInfo.name != "Tilemap" && hitInfo.tag != "Light" && hitInfo.tag != "Fire" && hitInfo.tag != "Sign") { MyEnemyHealth enemy = hitInfo.GetComponent <MyEnemyHealth>(); if (enemy != null) { enemy.TakeDamage(damage); } GameObject boom = Instantiate(impactEffect, transform.position, transform.rotation); Destroy(gameObject); Destroy(boom, time); } }