void Start() { //鱼群数组初始化 yuqun = new List <Yu>(); //遍历鱼群 for (int i = 0; i < fishNum; i++) { //生成预制体 位置随机 旋转随机 Yu yu = Instantiate(fishPre, transform.position + new Vector3(Random.Range(-range, range), Random.Range(-range, range), Random.Range(-range, range)), Random.rotation).AddComponent <Yu>(); //设置不受重力影响 yu.gameObject.AddComponent <Rigidbody>().useGravity = false; //设置Tag yu.tag = thisTag; //设置父类 yu.transform.SetParent(transform); yu.yuqun = this; //存入鱼群数组 yuqun.Add(yu); } }
//和朋友保持的距离 Vector3 KeepFriendsDisVelocity(List <Yu> friends) { float dis = 999; Yu yu = null; foreach (var item in friends) { //返回本身的距离和朋友数组 之间的平均值 float d = Vector3.Distance(transform.position, item.transform.position); //如果平均值小于 Dis if (d < dis) { //Dis 等于平均值 并且 item 等于 yu dis = d; yu = item; } } if (yu != null) { //中心点位置计算 return((yu.transform.position - transform.position).normalized * Mathf.Clamp((dis - yuqun.keepFriendDis) / yuqun.keepFriendDis, -1f, 1f) * yuqun.keepFriendDisWeight); } else { //否则 位置等于 0 return(Vector3.zero); } }
private void InstantiateCharacters() { Wally = InitLogoHelper(nameof(Wally), canvas.transform, unitWidth); Gen = InitLogoHelper(nameof(Gen), canvas.transform, unitWidth); Yu = InitLogoHelper(nameof(Yu), canvas.transform, unitWidth); Wen = InitLogoHelper(nameof(Wen), canvas.transform, unitWidth); Laurence = InitLogoHelper(nameof(Laurence), canvas.transform, unitWidth); Yu.GetComponent <RectTransform>().sizeDelta *= 0.82f; }
private void SetUpSymbolPositions() { ExclamationMark.transform.localPosition = wallyTarget * 0.9f + new Vector3( Wally.GetComponent <RectTransform>().sizeDelta.x / 2f * 1.1f, Wally.GetComponent <RectTransform>().sizeDelta.y / 2f * 1.1f, 0); QuestionMark.transform.localPosition = yuTarget + new Vector3( Yu.GetComponent <RectTransform>().sizeDelta.x / 2.8f, Yu.GetComponent <RectTransform>().sizeDelta.y / 2.5f, 0); LaurenceMark.transform.localPosition = laurenceTarget * 0.9f + new Vector3( Laurence.GetComponent <RectTransform>().sizeDelta.x / 2.3f, Laurence.GetComponent <RectTransform>().sizeDelta.y / 9.5f, 0); }
private void SetActive() { Gen.SetActive(true); Laurence.SetActive(true); Wen.SetActive(true); Wally.SetActive(true); Yu.SetActive(true); QuestionMark.SetActive(true); ExclamationMark.SetActive(true); LaurenceMark.SetActive(true); TBoundary.SetActive(true); TColor.SetActive(true); S1Boundary.SetActive(true); S1Color.SetActive(true); S2Boundary.SetActive(true); S2Color.SetActive(true); }
private void DoFadingOut() { float duration = 1.5f; Wally.GetComponent <Image>().CrossFadeAlpha(0, duration, false); Gen.GetComponent <Image>().CrossFadeAlpha(0, duration, false); Laurence.GetComponent <Image>().CrossFadeAlpha(0, duration, false); Yu.GetComponent <Image>().CrossFadeAlpha(0, duration, false); Wen.GetComponent <Image>().CrossFadeAlpha(0, duration, false); QuestionMark.GetComponent <Image>().CrossFadeAlpha(0, duration, false); ExclamationMark.GetComponent <Image>().CrossFadeAlpha(0, duration, false); LaurenceMark.GetComponent <Image>().CrossFadeAlpha(0, duration, false); TBoundary.GetComponent <Image>().CrossFadeAlpha(0, duration, false); TColor.GetComponent <Image>().CrossFadeAlpha(0, duration, false); S1Boundary.GetComponent <Image>().CrossFadeAlpha(0, duration, false); S1Color.GetComponent <Image>().CrossFadeAlpha(0, duration, false); S2Boundary.GetComponent <Image>().CrossFadeAlpha(0, duration, false); S2Color.GetComponent <Image>().CrossFadeAlpha(0, duration, false); Destroy(); }
private void SetUpTargetPositions() { genTarget = new Vector3(0.16f * width - width / 2f, GetTargetY(Gen, height), 0); wallyTarget = new Vector3(0.35f * width, GetTargetY(Wally, height), 0f); laurenceTarget = new Vector3(0.1f * width, GetTargetY(Laurence, height), 0f); wenTarget = new Vector3(-0.125f * width, GetTargetY(Wen, height), 0f); yuTarget = new Vector3(-0.125f * width, GetTargetY(Yu, height), 0f) + new Vector3(0f, Wen.GetComponent <RectTransform>().sizeDelta.y - 0.16f * Yu.GetComponent <RectTransform>().sizeDelta.y, 0f); }