void OnCollisionEnter2D(Collision2D other) { // Friendly code if (friendlyBullet) { EnemyController enemy = other.collider.GetComponent <EnemyController>(); if (enemy != null) { enemy.Stun(bulletStun); enemy.Damage(bulletDamage); } } // Enemy code else { PlayerController player = other.collider.GetComponent <PlayerController>(); if (player != null) { HealthBar.instance.changeValue(-bulletDamage); PlayerController.instance.PlayHitSound(); } } // If it hit the wall WallBoom wall = other.collider.GetComponent <WallBoom>(); if (wall != null) { wall.PlayBoom(); } // Instantiate explode Instantiate(particles, transform.position, transform.rotation); Destroy(gameObject); }
void Awake() { instance = this; }