Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class hitBox : MonoBehaviour
  7. {
  8.     public float knockback;
  9.     private Rigidbody rb;
  10.  
  11.     public Transform playerPos;
  12.     private enemy enemy;
  13.  
  14.     public float dmg;
  15.    
  16.  
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.        
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.        
  27.     }
  28.  
  29.     private void OnTriggerEnter(Collider other)
  30.     {
  31.         if (other.CompareTag("Enemy"))
  32.         {
  33.             enemy = other.GetComponent<enemy>();
  34.             rb = other.GetComponent<Rigidbody>();
  35.             Vector3 direction = (other.transform.position - playerPos.position).normalized;
  36.             enemy.agent.enabled = false;
  37.             enemy.TakeDamage(dmg);
  38.             rb.AddForce(new Vector3(direction.x,0,0)*knockback);
  39.             Debug.Log("Hit Enemy");
  40.            
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement