Advertisement
johnnygoodguy2000

DamageEnemy.cs

May 2nd, 2024 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Animations;
  5.  
  6.  
  7.  
  8. public class DamageEnemy : MonoBehaviour
  9. {
  10.     public int damageToGive; // How much damage the object should do to the enemy
  11.     public float bounceOnEnemy; // Bounce velocity when colliding with an enemy
  12.  
  13.     private Rigidbody2D myRigidbody2D;
  14.  
  15.     void Start()
  16.     {
  17.         myRigidbody2D = transform.parent.GetComponent<Rigidbody2D>(); // Get the Rigidbody2D component of the player
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.        
  24.     }
  25.  
  26.     void OnTriggerEnter2D(Collider2D other)
  27.  
  28.    
  29.     {
  30.         Debug.Log("OnTriggerEnter2D called"); // Add this line to check if OnTriggerEnter2D is being called
  31.  
  32.         if (other.tag == "Enemy") // Check if the colliding object is tagged as "Enemy"
  33.  
  34.         {  
  35.             other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
  36.             myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.        /* if (other.tag == "Enemy")
  44.         {
  45.             other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
  46.             myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
  47.        
  48.         if (other.CompareTag("Enemy")) // Check if the colliding object is tagged as "Enemy"
  49.         {
  50.           //  Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
  51.            // other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
  52.             //Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
  53.            // myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
  54.            // Vector2 bounceForce = new Vector2(0f, bounceOnEnemy);// Create a new Vector2 with the bounce velocity
  55.             //debug.Log(bounceForce);
  56.             //myRigidbody2D.AddForce(bounceForce, ForceMode2D.Impulse); // Apply bouncing effect
  57.              }*/
  58.  
  59.            
  60.  
  61.        
  62.             Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
  63.         }
  64.     }
  65. }
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement