using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class FishManage : MonoBehaviour { //// Start is called before the first frame update //public Transform fishschoolObj, ParticleSystemobj; //public float deleTime1, deleScaleTime1; //public Vector3 ScalePos1; //public float deleTime2, deleScaleTime2; //public Vector3 ScalePos2; //public float deleTime3, deleScaleTime3; //public Vector3 ScalePos3; //public float PlayerdeleScaleTime; //public Vector3 PlayerScaleMaxPos; //public Vector3 PlayerScaleMiniPos; //public float ToPlayerSpeed; //private float distacneToPlayer; //private Vector3 Player; public Transform Group; public TankBehaviour []Finsh;//鱼儿 public Transform[] FishPos;//人群靠近后逃跑鱼群游动自动AI位置 private int _isFunction = 1;//当为1的时候,启用鱼群自动导航状态, public Transform startPosition;//Group初始位置 private float distacneToPlayer;//人物距离位置 public GameObject player;//玩家 private bool _IsWhetherToPlayer = true;//开始走向人物 public bool _isVuforia;//判断为SvrCamera还是vuforiaCamera; void Start() { //if (!_isVuforia) //{ // player = SvrManager.Instance.head.gameObject; //} StartCoroutine(RandomFunction()); //this.gameObject.GetComponent().onClick.AddListener(() => //{ //}); } ////// Update is called once per frame private int getRangeNum = 0; //最后输出的与上次随机数不同的随机数 public int GetRangeNum { get => getRangeNum; set { getRangeNum = value; if (getRangeNum == 0) { // Group.transform.position = FishPos[0].position;\ Group.DOMove(FishPos[0].transform.position, 1f, false);//deleTime为规定时间内移动到位置 } else if (getRangeNum == 1) { // Group.transform.position = FishPos[1].position; Group.DOMove(FishPos[1].transform.position, 1f, false);//deleTime为规定时间内移动到位置 } else if (getRangeNum == 2) { //Group.transform.position = FishPos[2].position; Group.DOMove(FishPos[2].transform.position, 1f, false);//deleTime为规定时间内移动到位置 } if (_IsWhetherToPlayer==true) { StartCoroutine(FinshPos1(20f)) ; _IsWhetherToPlayer = false; } } } int rangeRadomNum = 0; //每次随机产生的随机数,用于与上次进行比较 int numCount = 0; //用于统计每次输出的数,方便观察 int oneType=0; IEnumerator RandomFunction() { while (_isFunction == 1) { if (oneType == 0) { yield return new WaitForSeconds(0.1f); StartCoroutine(SpeedUpFinshMessage(0.1f, 30, 100)); StartCoroutine(SpeedDownFinshMessage(2f, 9, 40)); } else { yield return new WaitForSeconds(7f); } numCount++; do { rangeRadomNum = Random.Range(0, 2); } while (GetRangeNum == rangeRadomNum); GetRangeNum = rangeRadomNum; oneType++; // Debug.Log("第" + numCount.ToString() + "得到的随机数:" + GetRangeNum); } while (_isFunction==2) { yield return new WaitForSeconds(1f); distacneToPlayer = Vector3.Distance(Group.transform.position, player.transform.position); // Debug.Log("第数:" + distacneToPlayer); if (distacneToPlayer <= 1.2) { _IsWhetherToPlayer = true; _isFunction = 1; StartCoroutine(RandomFunction()); } else { Group.transform.position = startPosition.position; } } } public IEnumerator FinshPos1(float PosNum) { yield return new WaitForSeconds(PosNum); StopAllCoroutines(); _isFunction = 2; StartCoroutine(RandomFunction()); oneType = 0; StartCoroutine(SpeedUpFinshMessage(0.1f, 13, 60)) ; StartCoroutine(SpeedDownFinshMessage(2f, 9, 40)) ; // Group.DOMove(FishPos[PosNum].transform.position, deleTime, false);//deleTime为规定时间内移动到位置 } /// /// 加速 /// /// /// /// /// public IEnumerator SpeedUpFinshMessage(float deletime ,float Speed, float RotateSpeed ) { yield return new WaitForSeconds(deletime); for (int i = 0,count= Finsh.Length; i < count; i++) { Finsh[i].moveSpeed = Speed+i; Finsh[i].rotateSpeed = RotateSpeed+i; } } /// /// 减速 /// /// /// /// /// public IEnumerator SpeedDownFinshMessage(float deletime, float Speed, float RotateSpeed) { yield return new WaitForSeconds(deletime); for (int i = 0, count = Finsh.Length; i < count; i++) { Finsh[i].moveSpeed = Speed + i; Finsh[i].rotateSpeed = RotateSpeed + i; } } ///// ///// 放大鱼群 ///// ///// ///// ///// ///// //public IEnumerator FishMoveToPlayer( float intervalTime, Vector3 ScaleSize, float deleScaleTime) //{ // yield return new WaitForSeconds(intervalTime); // ParticleSystemobj.DOScale(ScaleSize, deleScaleTime); //deleScaleTime为规定时间内放大 //} ///// ///// 到达人物位置 ///// ///// //public IEnumerator ArrivePlayerPos(float intervalTime, Vector3 ScaleSize, float deleScaleTime) //{ // yield return new WaitForSeconds(intervalTime); // ParticleSystemobj.DOScale(ScaleSize, deleScaleTime); //deleScaleTime为规定时间内放大 // // Debug.Log("缩小鱼群"); // yield return new WaitForSeconds(5); // _isFunction = 1; // StartCoroutine(RandomFunction()); //} }