锥形飞

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Ongroup : MonoBehaviour {

public enum AttackType
{
	right,
	left
}
public enum HurtType
{
	Normal,
	Prefect,
	Easy
}
public AttackType attackType;
public HurtType hurtType;
public float MaxAngle = 120;
int Number;
float SingleAngle;
Fly[] flys;
// Use this for initialization
void Start () {
	Number = transform.childCount;
	SingleAngle = MaxAngle / Number;
	flys = GetComponentsInChildren<Fly>();
}
private void Update()
{
	if (Input.GetMouseButtonDown(0))
	{
		StartFly();
	}
}

private void StartFly()
{
	float baseradius = 1f;
	switch (attackType)
	{
		case AttackType.right:
			SingleAngle += 100f;
			break;
		case AttackType.left:
			SingleAngle -= 30f;
			break;
	}
	switch (hurtType)
	{
		case HurtType.Normal:
			baseradius = 1.5f;
			break;
		case HurtType.Prefect:
			baseradius = 2f;
			break;
		case HurtType.Easy:
			baseradius = 1f;
			break;
	}
	Debug.LogError("flys.Length:"+flys.Length);
	foreach(var item in flys)
	{
		
		float XRotationAngle = 15f;
		Vector3 flyup = Vector3.up;
		Vector3 flyxz = Vector3.right * baseradius;//根据半径长度算向量大小
												   //这个怪物在这一组中的角度分配
		flyxz = Quaternion.AngleAxis(SingleAngle, Vector3.up) * flyxz;//旋转角度
																	  //算和向量
		Vector3 base_out = flyup + flyxz;
		//将向量根据forward倾斜
		base_out = Quaternion.AngleAxis(XRotationAngle, Vector3.forward) * base_out.normalized;
		float FlySpeed = Random.Range(1, 1.5f) * Random.Range(1, 3f);
		//飞散速度
		base_out *= FlySpeed *1.5f;
		//求角速度
		Vector3 AngleVelocity = Vector3.Cross(Vector3.up, base_out);
		AngleVelocity *= 3f;
		item.StartFly(base_out,AngleVelocity);
	}
	
}

}

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页