123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- 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<SCButton>().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为规定时间内移动到位置
- }
- /// <summary>
- /// 加速
- /// </summary>
- /// <param name="deletime"></param>
- /// <param name="Speed"></param>
- /// <param name="RotateSpeed"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 减速
- /// </summary>
- /// <param name="deletime"></param>
- /// <param name="Speed"></param>
- /// <param name="RotateSpeed"></param>
- /// <returns></returns>
- 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;
- }
- }
- ///// <summary>
- ///// 放大鱼群
- ///// </summary>
- ///// <param name="intervalTime"></param>
- ///// <param name="ScaleSize"></param>
- ///// <param name="deleScaleTime"></param>
- ///// <returns></returns>
- //public IEnumerator FishMoveToPlayer( float intervalTime, Vector3 ScaleSize, float deleScaleTime)
- //{
- // yield return new WaitForSeconds(intervalTime);
- // ParticleSystemobj.DOScale(ScaleSize, deleScaleTime); //deleScaleTime为规定时间内放大
- //}
- ///// <summary>
- ///// 到达人物位置
- ///// </summary>
- ///// <returns></returns>
- //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());
- //}
- }
|