123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using DG.Tweening;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using UnityEngine;
- public class NPC_QW : MonoBehaviour
- {
- // Start is called before the first frame update
- 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;//x为转弯速度,y为规定时间到达。
- public Vector2 turnAnddeletTime1;//x为转弯速度,y为规定时间到达。
- public Vector2 turnAnddeletTime2;//x为转弯速度,y为规定时间到达。
- public Vector2 turnAnddeletTime3;//x为转弯速度,y为规定时间到达。
- public bool _isVuforia;//判断为SvrCamera还是vuforiaCamera;
- public int index
- {
- get => _index++;
- set
- {
- }
- }
- private void OnEnable()
- {
- //if (!_isVuforia)
- //{
- // player = SvrManager.Instance.head.gameObject;
- //}
- StartCoroutine(CrabAI());
- }
- void Start()
- {
- }
- //private void Update()
- //{
- // //_targetPoint = v3Point[index];
- // // this.transform.DOLocalPath(v3Point[], 10f, PathType.CatmullRom);
- // // this.transform.DOLookAt(goToPoint[0].position, 0.5f);
- // // this.transform.DOMove(goToPoint[0].transform.position, 10f, false);
- // //transform.LookAt(v3Point[index]);
- // //transform.DOBlendableLocalMoveBy(Vector3.forward * 10, 3);
- // if (Input.GetKeyUp(KeyCode.A))
- // {
- // CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- // }
- // if (Input.GetKeyUp(KeyCode.B))
- // {
- // CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- // }
- // if (Input.GetKeyUp(KeyCode.C))
- // {
- // CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- // }
- // if (Input.GetKeyUp(KeyCode.D))
- // {
- // CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- // }
- //}
- public IEnumerator CrabAI()
- {
- while (true)
- {
- yield return new WaitForSeconds(1f);
- if(player!=null)
- {
- distacneToPlayer = Vector3.Distance(this.transform.position, player.transform.position);
- // Debug.Log(string.Format("{0}====={1}", transform.name, distacneToPlayer));
- if (distacneToPlayer < 1.8f && _IsRun == true)
- {
- // anim.SetBool("IsRun", true);
- // anim.SetBool("isWait", false);
- // this.transform.DOMove(goToPoint.transform.position, 10f, false);
- if (_index == 0)
- {
- // CrabPath(1f,5f);
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 1)
- {
- // CrabPath(1f,5f);
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 2)
- {
- // CrabPath(1f,5f);
- CrabPath(turnAnddeletTime.x, turnAnddeletTime.y);
- }
- else if (_index == 3)
- {
- // CrabPath(1f, 5f);
- 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);
- // Debug.Log("Run");
- StartCoroutine(Stoppath(turnTime, deletTime));
- }
- public IEnumerator Stoppath(float turnTime, float deletTime)
- {
- float Time = deletTime - 0.35f;
- yield return new WaitForSeconds(Time);
- // this.transform.DOLookAt(goToPoint[_index].position, turnTime);
- // Debug.Log("stop");
- anim.SetBool("IsRun", false);
- _index++;
- _IsRun = true;
- if (_index >= goToPoint.Length)
- {
- _index = 0;
- }
- }
- }
|