Guest User

Untitled

a guest
Feb 14th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Enemy : MonoBehaviour
  6. {
  7.     [SerializeField]
  8.     private Transform player;
  9.     public GameObject Player;
  10.     public int health =50;
  11.     public GameObject Bullet;
  12.     private bool start1=false;
  13.     public bool start2=false;
  14.     IEnumerator Kick()
  15.     {
  16.         yield return new WaitForSeconds(2f);
  17.         Player.GetComponent<Player>().health -= 5;
  18.         start1 = false;
  19.     }
  20.     IEnumerator Hurt()
  21.     {
  22.         yield return new WaitForSeconds(1f);
  23.         health -= 5;
  24.         StartCoroutine(Hurt());
  25.         start2 = false;
  26.     }
  27.     void Update()
  28.     {
  29.         this.transform.LookAt(player);
  30.         this.transform.Translate(0, 0, 0.8f);
  31.         if (Vector3.Distance(player.position, this.transform.position) <= 7)
  32.         {
  33.             if (start1 == false)
  34.             {
  35.                 StartCoroutine(Kick());
  36.                 start1 = true;
  37.             }
  38.         }
  39.     }
  40.     private void OnTriggerEnter(Collider other)
  41.     {
  42.         if (other.transform.tag == "Bullet")
  43.         {
  44.             if (start2==false)
  45.             {
  46.                 StartCoroutine(Hurt());
  47.                 start2 = true;
  48.             }
  49.         }
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment