Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class hitBox : MonoBehaviour
- {
- public float knockback;
- private Rigidbody rb;
- public Transform playerPos;
- private enemy enemy;
- public float dmg;
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Enemy"))
- {
- enemy = other.GetComponent<enemy>();
- rb = other.GetComponent<Rigidbody>();
- Vector3 direction = (other.transform.position - playerPos.position).normalized;
- enemy.agent.enabled = false;
- enemy.TakeDamage(dmg);
- rb.AddForce(new Vector3(direction.x,0,0)*knockback);
- Debug.Log("Hit Enemy");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement