void OnCollisionEnter2D(Collision2D collision) { GameObject other = collision.collider.gameObject; if (other != gameObject) { if (other.CompareTag("Enemy")) { TakeDamage(20); Destroy(other); FindObjectOfType <EnemySpawner>().EnemyDied(); PlayerParticle(); bloodSplash.SpawnEnemySplash(); FindObjectOfType <AudioManager>().Play("PlayerHit"); StartCoroutine(shake.Shake(.14f, .4f)); if (currentHealth == 0) { FindObjectOfType <AudioManager>().Play("PlayerDeath"); PlayerParticle(); FindObjectOfType <GameManager>().EndGame(); } } } }
void Update() { Vector2 currentPosition = new Vector2(transform.position.x, transform.position.y); Vector2 newPosition = currentPosition + velocity * Time.deltaTime; Debug.DrawLine(currentPosition + offset, newPosition + offset, Color.red); RaycastHit2D[] hits = Physics2D.LinecastAll(currentPosition + offset, newPosition + offset); foreach (RaycastHit2D hit in hits) { GameObject other = hit.collider.gameObject; if (other != sprayer) { // Debug.Log(hit.collider.gameObject); if (other.CompareTag("Enemy")) { BulletParticle(); EnemyParticle(); camRipple.RippleEffect(); FindObjectOfType <AudioManager>().Play("EnemyHit"); spawner.EnemyDied(); Destroy(gameObject); Destroy(other); bloodSplash.SpawnEnemySplash(); Debug.Log(other.name); break; } if (other.CompareTag("Walls")) { BulletParticle(); FindObjectOfType <AudioManager>().Play("WallHit"); Destroy(gameObject); Debug.Log(other.name); break; } } } transform.position = newPosition; }