Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- [SerializeField]
- private Transform player;
- public GameObject Player;
- public int health =50;
- public GameObject Bullet;
- private bool start1=false;
- public bool start2=false;
- IEnumerator Kick()
- {
- yield return new WaitForSeconds(2f);
- Player.GetComponent<Player>().health -= 5;
- start1 = false;
- }
- IEnumerator Hurt()
- {
- yield return new WaitForSeconds(1f);
- health -= 5;
- StartCoroutine(Hurt());
- start2 = false;
- }
- void Update()
- {
- this.transform.LookAt(player);
- this.transform.Translate(0, 0, 0.8f);
- if (Vector3.Distance(player.position, this.transform.position) <= 7)
- {
- if (start1 == false)
- {
- StartCoroutine(Kick());
- start1 = true;
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.transform.tag == "Bullet")
- {
- if (start2==false)
- {
- StartCoroutine(Hurt());
- start2 = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment