Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.AI;
- public class enemy : MonoBehaviour
- {
- public Transform target;
- private Transform player;
- private Rigidbody rb;
- public float spd;
- public bool isHit;
- private float hitStun;
- public float hitTimer = 1;
- public float hp;
- public NavMeshAgent agent;
- // Start is called before the first frame update
- void Start()
- {
- agent = GetComponent<NavMeshAgent>();
- rb = GetComponent<Rigidbody>();
- player = GameObject.Find("Player").transform;
- target = player;
- }
- // Update is called once per frame
- void Update()
- {
- if (isHit && Time.time > hitStun)
- {
- isHit = false;
- }
- if (hp <= 0)
- {
- Destroy(gameObject);
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Weapon"))
- {
- hitStun = Time.time + hitTimer;
- isHit = true;
- }
- }
- private void FixedUpdate()
- {
- if (!isHit)
- {
- agent.enabled = true;
- if (agent.enabled)
- {
- agent.destination = target.transform.position;
- }
- }
- }
- public void TakeDamage(float dmg)
- {
- hp -= dmg;
- }
- }
Add Comment
Please, Sign In to add comment