Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TrolAI_II : MonoBehaviour
- {
- public GameObject player;
- public Animator anim; // Animator to animate character behavior
- GameObject TrolEnemy = null;
- public List<GameObject> waypoints = new List<GameObject>();
- private int num = 0;
- public List<GameObject> TrollEnemies = new List<GameObject>();
- // Start is called before the first frame update
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- patrol();
- if (TrollEnemies.Capacity > 0)
- {
- anim.SetBool("Walk", true);
- Debug.Log("hhghg");
- float enemyDistance = Vector3.Distance(TrollEnemies[0].gameObject.transform.position, this.transform.position);
- gameObject.transform.LookAt((TrollEnemies[0].gameObject.transform.position));
- gameObject.transform.position += gameObject.transform.forward * 1 * Time.deltaTime;
- if (enemyDistance <2f)
- {
- gameObject.transform.position += gameObject.transform.forward * 0 * Time.deltaTime;
- anim.SetBool("Attack", true);
- }
- }
- // Find closest enemy
- // Attack closest enemy
- }
- private void patrol()
- {
- float dist = Vector3.Distance(gameObject.transform.position, waypoints[num].transform.position);
- if (dist > 1)
- {
- anim.SetBool("Walk", true);
- gameObject.transform.LookAt(waypoints[num].transform.position);
- gameObject.transform.position += gameObject.transform.forward * 1 * Time.deltaTime;
- }
- else
- {
- if (num + 1 == waypoints.Capacity)
- {
- num = 0;
- }
- else
- {
- num++;
- }
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag == "Player")
- {
- TrollEnemies.Add(other.gameObject);
- Debug.Log("aghhhhhh!!!!");
- }
- }
- private void OnTriggerExit(Collider other)
- {
- TrollEnemies.Remove(GameObject.Find(other.name));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement