Advertisement
Lyim

Untitled

Apr 20th, 2021
1,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyDamage : MonoBehaviour
  6. {
  7.  
  8.     public GameObject enemyCorpse;
  9.  
  10.     private void OnCollisionEnter(Collision collision)
  11.     {
  12.         Debug.Log("Collided"); // This is not printing.
  13.         // Check if collision is with player.
  14.         if (collision.collider.gameObject.tag == "Player")
  15.         {
  16.             PlayerHealth playerHealth = collision.collider.gameObject.GetComponent<PlayerHealth>();
  17.             GameObject corpseClone = Instantiate(enemyCorpse, transform.position, Quaternion.identity);
  18.             Destroy(gameObject);
  19.             playerHealth.health -= 1;
  20.         }
  21.     }
  22.  
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement