void OnCollisionEnter2D(Collision2D other) { if (other.collider.CompareTag("Player")) { player.Damage(1f); } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { player.Damage(1f); } }
IEnumerator Shoot() { RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.right); Audio.PlayOneShot(AttackClip, 0.5f); if (hitInfo) { Player1 player = hitInfo.transform.GetComponent <Player1>(); Enemy enemy = hitInfo.transform.GetComponent <Enemy>(); if (player != null) { player.Damage(); } else if (enemy != null) { enemy.Damage(); } //Random.Range(fireY - errorDistance, fireY + errorDistance) firePoint.position = new Vector3(firePoint.position.x, fireY, firePoint.position.z); lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, hitInfo.point); } else { lineRenderer.SetPosition(0, firePoint.position); lineRenderer.SetPosition(1, firePoint.position + firePoint.right * 100); } lineRenderer.enabled = true; yield return(new WaitForSeconds(0.02f)); lineRenderer.enabled = false; }
void OnCollisionEnter2D(Collision2D other) { if (other.gameObject.CompareTag("Player")) { player.Damage(1.0f); gameObject.GetComponent <Collider2D>().enabled = false; } }
// Update is called once per frame void Update() { //when the player doesnt equal null if (player != null) { //perform damage function player.Damage(damage, knockbackDirection, knockBackForce); } }
void OnTriggerEnter2D(Collider2D other) { //dont allow the trigger to collide with another trigger if (other.isTrigger || other.gameObject.layer == LayerMask.NameToLayer("invisibleGround")) { return; } var damagable = other.GetComponent <IDamagable>(); if (damagable != null) { //damage enemies on collision damagable.TakeDamage(damage); } if (other.CompareTag("Player")) { player.Damage(damage); } //destroy the bullet on collision Destroy(gameObject); }