Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TrolAI_II : MonoBehaviour
  6. {
  7.  
  8.     public GameObject player;
  9.     public Animator anim; // Animator to animate character behavior
  10.     GameObject TrolEnemy = null;
  11.     public List<GameObject> waypoints = new List<GameObject>();
  12.     private int num = 0;
  13.  
  14.     public List<GameObject> TrollEnemies = new List<GameObject>();
  15.  
  16.     // Start is called before the first frame update
  17.     void Start()
  18.     {
  19.        
  20.     }
  21.  
  22.     // Update is called once per frame
  23.     void Update()
  24.     {
  25.  
  26.        
  27.         patrol();
  28.  
  29.  
  30.         if (TrollEnemies.Capacity > 0)
  31.         {
  32.             anim.SetBool("Walk", true);
  33.             Debug.Log("hhghg");
  34.             float enemyDistance = Vector3.Distance(TrollEnemies[0].gameObject.transform.position, this.transform.position);
  35.             gameObject.transform.LookAt((TrollEnemies[0].gameObject.transform.position));
  36.             gameObject.transform.position += gameObject.transform.forward * 1 * Time.deltaTime;
  37.             if (enemyDistance <2f)
  38.             {
  39.                 gameObject.transform.position += gameObject.transform.forward * 0 * Time.deltaTime;
  40.                 anim.SetBool("Attack", true);
  41.  
  42.             }
  43.  
  44.         }
  45.  
  46.                 // Find closest enemy
  47.                 // Attack closest enemy
  48.     }
  49.            
  50.  
  51.  
  52.    
  53.     private void patrol()
  54.     {
  55.         float dist = Vector3.Distance(gameObject.transform.position, waypoints[num].transform.position);
  56.         if (dist > 1)
  57.         {
  58.             anim.SetBool("Walk", true);
  59.             gameObject.transform.LookAt(waypoints[num].transform.position);
  60.             gameObject.transform.position += gameObject.transform.forward * 1 * Time.deltaTime;
  61.         }
  62.         else
  63.         {
  64.             if (num + 1 == waypoints.Capacity)
  65.             {
  66.                 num = 0;
  67.             }
  68.             else
  69.             {
  70.                 num++;
  71.             }
  72.         }
  73.  
  74.  
  75.     }
  76.     private void OnTriggerEnter(Collider other)
  77.     {
  78.         if (other.tag == "Player")
  79.         {
  80.  
  81.             TrollEnemies.Add(other.gameObject);
  82.             Debug.Log("aghhhhhh!!!!");
  83.         }
  84.     }
  85.  
  86.     private void OnTriggerExit(Collider other)
  87.     {
  88.         TrollEnemies.Remove(GameObject.Find(other.name));
  89.  
  90.     }
  91.  
  92.  
  93.  
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement