Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Animations;
- public class DamageEnemy : MonoBehaviour
- {
- public int damageToGive; // How much damage the object should do to the enemy
- public float bounceOnEnemy; // Bounce velocity when colliding with an enemy
- private Rigidbody2D myRigidbody2D;
- void Start()
- {
- myRigidbody2D = transform.parent.GetComponent<Rigidbody2D>(); // Get the Rigidbody2D component of the player
- }
- // Update is called once per frame
- void Update()
- {
- }
- void OnTriggerEnter2D(Collider2D other)
- {
- Debug.Log("OnTriggerEnter2D called"); // Add this line to check if OnTriggerEnter2D is being called
- if (other.tag == "Enemy") // Check if the colliding object is tagged as "Enemy"
- {
- other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
- myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
- /* if (other.tag == "Enemy")
- {
- other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
- myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
- if (other.CompareTag("Enemy")) // Check if the colliding object is tagged as "Enemy"
- {
- // Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
- // other.GetComponent<EnemyHealthManager>().giveDamage(damageToGive); // Deal damage to the enemy
- //Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
- // myRigidbody2D.velocity = new Vector2(myRigidbody2D.velocity.x, bounceOnEnemy); // Apply bounce velocity
- // Vector2 bounceForce = new Vector2(0f, bounceOnEnemy);// Create a new Vector2 with the bounce velocity
- //debug.Log(bounceForce);
- //myRigidbody2D.AddForce(bounceForce, ForceMode2D.Impulse); // Apply bouncing effect
- }*/
- Debug.Log("Colliding object tag: " + other.tag); // Log the tag of the colliding object
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement