private void AimAndShoot() { Vector2 shootingDirection = new Vector2(aim.x, aim.y); if (aim.magnitude > 0.0f) { crossHair.transform.localPosition = aim * 0.4f; crossHair.SetActive(true); shootingDirection.Normalize(); if (isAiming) { GameObject bullet = Instantiate(bulletPrefab, transform.position, Quaternion.identity); Bullet bulletScript = bullet.GetComponent <Bullet>(); Debug.Log("FIRE!"); bulletScript.velocity = shootingDirection * 4.5f; gunShot = GetComponent <AudioSource>(); gunShot.Play(0); shake.CamShake(); bulletScript.self = gameObject; bullet.transform.Rotate(0.0f, 0.0f, Mathf.Atan2(shootingDirection.y, shootingDirection.x) * Mathf.Rad2Deg); Destroy(bullet, 0.55f); } } else { crossHair.SetActive(false); } }
void OnTriggerEnter2D(Collider2D bullet) { if (bullet.gameObject.tag == "Bullet") { Debug.Log("ZombieShot!"); enemHealth = enemHealth - damageShot; //Destroy(gameObject); Instantiate(blood, transform.position, Quaternion.identity); shake.CamShake(); } if (enemHealth <= 0) { enemHealth = 0; } if (bullet.gameObject.tag == "Players") { int index = Random.Range(0, zombienoises.Length); groans = zombienoises[index]; audioSource.clip = groans; audioSource.Play(); } }