123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using DG.Tweening;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using UnityEngine;
- public class NPC_QW : MonoBehaviour
- {
-
- private float distacneToPlayer;
- public GameObject player;
- public Transform[] goToPoint;
- public Animator anim;
- private Transform _targetPoint;
- private int _index = 0;
- private bool _IsRun = true;
- public Vector2 turnAnddeletTime;
- public Vector2 turnAnddeletTime1;
- public Vector2 turnAnddeletTime2;
- public Vector2 turnAnddeletTime3;
- public bool _isVuforia;
- public int index
- {
- get => _index++;
- set
- {
- }
- }
- private void OnEnable()
- {
-
-
-
-
- StartCoroutine(CrabAI());
- }
- void Start()
- {
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public IEnumerator CrabAI()
- {
- while (true)
- {
- yield return new WaitForSeconds(1f);
- if(player!=null)
- {
- distacneToPlayer = Vector3.Distance(this.transform.position, player.transform.position);
-
- if (distacneToPlayer < 1.8f && _IsRun == true)
- {
-
-
-
- if (_index == 0)
- {
-
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 1)
- {
-
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 2)
- {
-
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 3)
- {
-
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- }
- }
-
- }
- }
- public void CrabPath(float turnTime, float deletTime)
- {
- _IsRun = false;
- anim.SetBool("IsRun", true);
- this.transform.DOLookAt(goToPoint[_index].position, turnTime);
- this.transform.DOMove(goToPoint[_index].transform.position, deletTime, false);
-
- StartCoroutine(Stoppath(turnTime, deletTime));
- }
- public IEnumerator Stoppath(float turnTime, float deletTime)
- {
- float Time = deletTime - 0.35f;
- yield return new WaitForSeconds(Time);
-
-
- anim.SetBool("IsRun", false);
- _index++;
- _IsRun = true;
- if (_index >= goToPoint.Length)
- {
- _index = 0;
- }
- }
- }
|